<?php
/**
 * 武汉市中心医院中间件
 *
 *
 * @author Jack
 */

namespace Whszxyy\Controller;

class WhszxyyControlucController
{
    // SoapClient 对象
    private $soap = FALSE;

    // 记录是否为正式环境
    private $isFormal = FALSE;

    //是否开启缓存
    private static $CACHE = false;

    // 医疗机构科室列表缓存建
    private static $CACHE_INSTITUTION_CLASS_LIST = 'CACHE_INSTITUTION_CLASS_LIST';


    //static $URL_API = 'http://59.175.191.226:9192/OrderTreat/services/HosiptalManager?wsdl';
    //正式库预约挂号20170615 add by jack
    static $URL_API = 'http://192.168.100.138:9192/OrderTreat/services/HosiptalManager?wsd';

    //绑卡专用 http://192.168.100.149:9192/OrderTreat/services/HosiptalManager?wsdl
    //static $CARD_URL_API = 'http://59.175.191.226:9192/OnlineManager/services/RegisterUserManager?wsdl';
    static $CARD_URL_API = 'http://192.168.100.138:9192/OnlineManager/services/RegisterUserManager?wsdl';//20170615 add by jack
    static $back_URL_API = "http://localhost:8091";
    //static $back_URL_API = "59.175.191.229";

    //医院id
    private $hospitalId;

    //厂商id
    private $requestId='512';
    private $requestId_Old='tcwy';  //武汉市中心医院老系统门诊缴费住院预交金授权ID

    //自助机id
    private $userId;

    /**
     * 构造函数
     */
    function __construct()
    {
        $this->hospitalId = 1;
        if (!method_exists($this, ACTION_NAME)) {
            $function = ACTION_NAME;
            A('Receive')->$function();
        }
    }


    public $hospitalKey = array(
        "1" => "7daf7603429012aeae417fa9beed9c75",
    );
    //正式地址
    //  static $URL_API = "http://125.64.9.81:8088/rmc/mobile/web";
    //  static $version = "2.2.7";
    //  private $token = "6a2967e64a994e54b533aa7942328179";
    //正式地址

    /**
     *医院院区列表
     * @param $requestid '厂商ID'
     */
    public function GetHospitalList()
    {
        //echo 11;die;
        //dump($URL_API);die();
        //echo C('URL_API');die();
        $client = new \SOAPClient('http://192.168.100.149:9192/OrderTreat/services/HosiptalManager?wsdl');//测试地址
        $xml=$this->get_GetHospitalList_xml(C('requestId'));
        //dump($xml);die();
        $function="GetHospitalList";
        $result_doclist=$this->Get_service_api($xml,$client,$function);
        //dump($URL_API);
        echo json_encode($result_doclist);
    }

    /**
     *获取科室信息
     * @param $hospitalId '院区ID'
     * @param $requestid '厂商ID'
     */
    public function hosInstitutionClass()
    {
        //dump(C('URL_API'));die();
        //$hospitalId = $_POST['districtCode'];   //院区ID
        $hospitalId='1001';
        //$client = new \SOAPClient(C('URL_API'));
        $client = new \SOAPClient('http://192.168.100.149:9192/OrderTreat/services/HosiptalManager?wsdl');//测试地址
        //$client = new \SOAPClient('http://59.175.191.226:9192/OrderTreat/services/HosiptalManager?wsdl');//测试地址
        //$client = new \SOAPClient('http://192.168.100.138:9192/OrderTreat/services/HosiptalManager?wsdl');
        $xml=$this->get_hosInstitutionClass_xml(C('requestId'),$hospitalId);
       // dump($xml);die();
        $function="GetDeptmentList";
        $result_doclist=$this->Get_service_api($xml,$client,$function);
        dump($result_doclist);die();
        echo json_encode($result_doclist);
    }

    /**
     *获取医生信息
     * @param $hospitalId '院区ID'
     * @param $requestid '厂商ID'
     * by jack 0427
     */
    public function dutyDoctor()
    {
        set_time_limit(0);
        //$hospitalId='1001';
        $hospitalId = $_POST['districtCode'];   //院区ID
        //$deptHisId = $_POST['deptHisId'];   //部门ID
        //$client = new \SOAPClient(C('URL_API'));
        $client = new \SOAPClient('http://192.168.100.149:9192/OrderTreat/services/HosiptalManager?wsdl');//测试地址
        $xml=$this->get_dutyDoctor_xml(C('requestId'),$hospitalId);
        //$kkk_docinfo= $this->queryDoctorInfoByOldId('1','1115');
        //dump($kkk_docinfo);
        $function="GetDoctorList";
        $result_doclist=$this->Get_service_api($xml,$client,$function);
        //dump($result_doclist['rowcountall']);
        $ywsz_jj=$result_doclist['data'];  
        //$res_data= $result_doclist['data']['data_row'];   
        if ($result_doclist['rowcountall'] == '1') {
            //echo '是一维数组';
                $t_docinfo= $this->DoctorInfoByDutyDoctor('1',$ywsz_jj['doctorno']);

                $returnArr['data'][0]['hospitalid']=$ywsz_jj['hospitalid'];
                $returnArr['data'][0]['hospitalname']=$ywsz_jj['hospitalname'];
                $returnArr['data'][0]['deptcode']=$ywsz_jj['deptcode'];//科室ID
                $returnArr['data'][0]['deptname']=$ywsz_jj['deptname'];//科室
                $returnArr['data'][0]['doctorno']=$ywsz_jj['doctorno'];//医生ID
                $returnArr['data'][0]['inputcode']=$ywsz_jj['inputcode'];//拼音码
                $returnArr['data'][0]['doctorname']=$ywsz_jj['doctorname'];//医生
                if($t_docinfo['errorMsg']=='成功')
                {
                    $returnArr['data'][0]['doctortitle']=$t_docinfo['data']['zc'];//职称
                    $returnArr['data'][0]['specialty']=$t_docinfo['data']['sc'];//擅长
                    $returnArr['data'][0]['doctordes']=$t_docinfo['data']['zjjj']; //简介
                    $returnArr['data'][0]['photo']=$t_docinfo['data']['photo']; //头像
                }else{
                    $returnArr['data'][0]['doctortitle']=$ywsz_jj['doctortitle'];//职称
                    $returnArr['data'][0]['specialty']=$ywsz_jj['specialty'];//擅长
                    $returnArr['data'][0]['doctordes']=$ywsz_jj['doctordes']; //简介
                    $returnArr['data'][0]['photo']=''; //头像
                };
                $returnArr['data'][0]['scheduleflag']=$ywsz_jj['scheduleflag'];//预约状态 1：有号可约  0：无号可约（停诊\约满\未开发等）
                $returnArr['data'][0]['realnamecheckin']=$ywsz_jj['realnamecheckin'];
                $returnArr['data'][0]['lastmodify']=$ywsz_jj['lastmodify'];

                if($returnArr['data'][0]['doctortitle']=='医生'){
                    $returnArr['data'][0]['doctortitle']='医师';
                } else if ($returnArr['data'][0]['doctortitle']=='主治医生') {
                    $returnArr['data'][0]['doctortitle']='主治医师';
                } else if ($returnArr['data'][0]['doctortitle']=='副主任医生') {
                    $returnArr['data'][0]['doctortitle']='副主任医师';
                } else if ($returnArr['data'][0]['doctortitle']=='主任医生') {
                    $returnArr['data'][0]['doctortitle']='主任医师';
                };

        } else {
            //echo '非是一维数组';
            foreach ($ywsz_jj as $k => $v) {

                $t_docinfo= $this->DoctorInfoByDutyDoctor('1',$ywsz_jj[$k]['doctorno']);

                $returnArr['data'][$k]['hospitalid']=$ywsz_jj[$k]['hospitalid'];
                $returnArr['data'][$k]['hospitalname']=$ywsz_jj[$k]['hospitalname'];
                $returnArr['data'][$k]['deptcode']=$ywsz_jj[$k]['deptcode'];//科室ID
                $returnArr['data'][$k]['deptname']=$ywsz_jj[$k]['deptname'];//科室
                $returnArr['data'][$k]['doctorno']=$ywsz_jj[$k]['doctorno'];//医生ID
                $returnArr['data'][$k]['inputcode']=$ywsz_jj[$k]['inputcode'];//拼音码
                $returnArr['data'][$k]['doctorname']=$ywsz_jj[$k]['doctorname'];//医生
                if($t_docinfo['errorMsg']=='成功')
                {
                    $returnArr['data'][$k]['doctortitle']=$t_docinfo['data']['zc'];//职称
                    $returnArr['data'][$k]['specialty']=$t_docinfo['data']['sc'];//擅长
                    $returnArr['data'][$k]['doctordes']=$t_docinfo['data']['zjjj']; //简介
                    $returnArr['data'][$k]['photo']=$t_docinfo['data']['photo']; //头像
                }else{
                    $returnArr['data'][$k]['doctortitle']=$ywsz_jj[$k]['doctortitle'];//职称 副主任医师
                    $returnArr['data'][$k]['specialty']=$ywsz_jj[$k]['specialty'];//擅长
                    $returnArr['data'][$k]['doctordes']=$ywsz_jj[$k]['doctordes']; //简介
                    $returnArr['data'][$k]['photo']=''; //头像
                };
                $returnArr['data'][$k]['scheduleflag']=$ywsz_jj[$k]['scheduleflag'];//预约状态 1：有号可约  0：无号可约（停诊\约满\未开发等）
                $returnArr['data'][$k]['realnamecheckin']=$ywsz_jj[$k]['realnamecheckin'];
                $returnArr['data'][$k]['lastmodify']=$ywsz_jj[$k]['lastmodify'];

                if($returnArr['data'][$k]['doctortitle']=='医生'){
                    $returnArr['data'][$k]['doctortitle']='医师';
                } else if ($returnArr['data'][$k]['doctortitle']=='主治医生') {
                    $returnArr['data'][$k]['doctortitle']='主治医师';
                } else if ($returnArr['data'][$k]['doctortitle']=='副主任医生') {
                    $returnArr['data'][$k]['doctortitle']='副主任医师';
                } else if ($returnArr['data'][$k]['doctortitle']=='主任医生') {
                    $returnArr['data'][$k]['doctortitle']='主任医师';
                };
            }
        };
        //dump($returnArr);
        echo json_encode($returnArr);
    }

    /**
     *获取武汉市中心医院HIS医生信息
     * @param $hospitalId '院区ID'
     * @param $requestid '厂商ID'
     * by jack 626 //DoctorInfoByDutyDoctor   直接通过医生ID查询医生的基本信息 职称简介擅长
     */
    function DoctorInfoByDutyDoctor($hospitalId,$doctorid)
    {
        $id = 'A0A2EA33-06E6-459E-A82F-D3A506CD593D';//医院分配的渠道ID
        //$doctorid = '4058';//医生ID
        $soap = new \SoapClient('http://192.168.0.79:3333/DoctorInfoService.asmx?wsdl');
        //dump($soap);die();
        $param["id"]=$id;
        $param["doctorid"]=$doctorid;

        $result=$soap->queryDoctorInfo($param);
        $data=$result->queryDoctorInfoResult;

        $tesres = $this->xml_to_array($data);
        if($tesres["documentinfo"]["resultcode"]!='100'){
            $returnArr['status'] = 2;
            $returnArr['errorMsg'] = $tesres["documentinfo"]["resultinfo"];
        }else{//格式化为标准接口模式
            $returnArr['status'] = 1;
            $returnArr['errorMsg'] = $tesres["documentinfo"]["resultinfo"];
            $returnArr['data']['Doctorid'] = $doctorid;//医生ID
            $returnArr['data']['Doctorsname'] = $tesres["documentinfo"]["root"]["name"];//医生姓名
            $returnArr['data']['Deptname'] = $tesres["documentinfo"]["root"]["department"];//科室
            $returnArr['data']['zc'] = $tesres["documentinfo"]["root"]["zc"];//医生职称
            $returnArr['data']['zjjj'] = $tesres["documentinfo"]["root"]["zjjj"];//医生简介
            $returnArr['data']['sc'] = $tesres["documentinfo"]["root"]["sc"];//医生擅长
            $returnArr['data']['photo'] = $tesres["documentinfo"]["root"]["photo"];//医生图片文件名
        }
        return($returnArr);
    }

    /**
     *获取医生排班表 getDoctorSource
     * @param $requestid '厂商ID'
     * @param string $docHisId 医生id
     * @param string $deptHisId 科室id  可为空
     * @param string $districtCode 院区id
     * @param string $outpdate_start 开始时间
     * @param string $outpdate_end 结束时间
     */
    public function getDoctorSource($hospitalId,$docHisId,$deptHisId,$districtCode,$outpdate_start,$outpdate_end)
    {
    
        //echo $hospitalId.'+'.$docHisId.'+'.$deptHisId.'+'.$districtCode;die();
        $hospitalId=$districtCode;//院区ID  
        //$client = new \SOAPClient(C('URL_API'));
        $client = new \SOAPClient('http://192.168.100.149:9192/OrderTreat/services/HosiptalManager?wsdl');//测试地址
        $xml=$this->get_getDoctorSource_xml(C('requestId'),$outpdate_start,$outpdate_end,$hospitalId,$deptHisId,$docHisId);
        //dump($xml);die();
        $function="GetScheduleList";
        $result_doclist=$this->Get_service_api($xml,$client,$function);
        $result_doclist['data']=$this->more_array_unique($result_doclist['data']);

        $te_arry=$result_doclist['data']['scheduleid'];
        //dump($result_doclist);die();
        if($result_doclist['returncode']!='1'){
            $returnArr['status'] = 2;
            $returnArr['errorMsg'] = isset($result_doclist['returncode'])?$result_doclist['returncode']:"访问异常！code:201";
            echo json_encode($returnArr);exit;
        }else{//格式化为标准接口模式
            $returnArr['status'] = 1;
            $returnArr['errorMsg'] = "查询成功！";
            if($te_arry){
                    $returnArr['data']['duty'][0]['RBASId']=$result_doclist['data']['scheduleid'];//排班ID
                    $returnArr['data']['duty'][0]['districtCode']=$result_doclist['data']['hospitalid']; 
                    $returnArr['data']['duty'][0]['date']=$result_doclist['data']['outpdate'];            //排班日期
                    $returnArr['data']['duty'][0]['timeinterval']=$result_doclist['data']['timeinterval']; //排班段  string 取值：AM：上午 PM：下午 AL：全天
                    $returnArr['data']['duty'][0]['deptcode']=$result_doclist['data']['deptcode'];        //科室ID
                    $returnArr['data']['duty'][0]['deptname']=$result_doclist['data']['deptname'];         //科室    
                    $returnArr['data']['duty'][0]['doctorno']=$result_doclist['data']['doctorno'];         //医生ID
                    $returnArr['data']['duty'][0]['doctorname']=$result_doclist['data']['doctorname'];     //医生
                    $returnArr['data']['duty'][0]['doctortitle']=$result_doclist['data']['doctortitle'];   //医生职称 如主任，副主任，主治，副主治，医师
                    $returnArr['data']['duty'][0]['outptypename']=$result_doclist['data']['outptypename']; //门诊类别 号别 如 平诊 急诊
                    $returnArr['data']['duty'][0]['clinicfee']=$result_doclist['data']['clinicfee'];       //诊查费
                    $returnArr['data']['duty'][0]['registrationfee']=$result_doclist['data']['registrationfee'];   //挂号费
                    $returnArr['data']['duty'][0]['reserveflag']=$result_doclist['data']['reserveflag'];   // 号源状态
                    $returnArr['data']['duty'][0]['schedulelist']=$result_doclist['data']['schedulelist'];   // 

            } else {
                foreach ($result_doclist['data'] as $k=>$v){

                    $returnArr['data']['duty'][$k]['RBASId']=$result_doclist['data'][$k]['scheduleid'];//排班ID
                    $returnArr['data']['duty'][$k]['districtCode']=$result_doclist['data'][$k]['hospitalid']; 
                    $returnArr['data']['duty'][$k]['date']=$result_doclist['data'][$k]['outpdate'];            //排班日期
                    $returnArr['data']['duty'][$k]['timeinterval']=$result_doclist['data'][$k]['timeinterval']; //排班段  string 取值：AM：上午 PM：下午 AL：全天
                    $returnArr['data']['duty'][$k]['deptcode']=$result_doclist['data'][$k]['deptcode'];        //科室ID
                    $returnArr['data']['duty'][$k]['deptname']=$result_doclist['data'][$k]['deptname'];         //科室    
                    $returnArr['data']['duty'][$k]['doctorno']=$result_doclist['data'][$k]['doctorno'];         //医生ID
                    $returnArr['data']['duty'][$k]['doctorname']=$result_doclist['data'][$k]['doctorname'];     //医生
                    $returnArr['data']['duty'][$k]['doctortitle']=$result_doclist['data'][$k]['doctortitle'];   //医生职称 如主任，副主任，主治，副主治，医师
                    $returnArr['data']['duty'][$k]['outptypename']=$result_doclist['data'][$k]['outptypename']; //门诊类别 号别 如 平诊 急诊
                    $returnArr['data']['duty'][$k]['clinicfee']=$result_doclist['data'][$k]['clinicfee'];       //诊查费
                    $returnArr['data']['duty'][$k]['registrationfee']=$result_doclist['data'][$k]['registrationfee'];   //挂号费
                    $returnArr['data']['duty'][$k]['reserveflag']=$result_doclist['data'][$k]['reserveflag'];   // 号源状态
                    $returnArr['data']['duty'][$k]['schedulelist']=$result_doclist['data'][$k]['schedulelist'];   // 

                 /*$newData[]=array(
                        'RBASId'=>$v['scheduleid'],         //排班ID
                        'districtCode'=>$v['hospitalid'], 
                        'date'=>$v['outpdate'],             //排班日期
                        'timeinterval'=>$v['timeinterval'], //排班段  string 取值：AM：上午 PM：下午 AL：全天
                        'deptcode'=>$v['deptcode'],         //科室ID
                        'deptname'=>$v['deptname'],         //科室    
                        'doctorno'=>$v['doctorno'],         //医生ID
                        'doctorname'=>$v['doctorname'],     //医生
                        'doctortitle'=>$v['doctortitle'],   //医生职称 如主任，副主任，主治，副主治，医师
                        'outptypename'=>$v['outptypename'], //门诊类别 号别 如 平诊 急诊
                        'clinicfee'=>$v['clinicfee'],       //诊查费
                        'registrationfee'=>$v['registrationfee'],   //挂号费
                        'reserveflag'=>$v['reserveflag'],   // 号源状态 
                        
                    //); 
                    */
                }
            }
        }
        //$returnArr['data']['duty'] = $newData;
       // dump($newData);exit;
        //dump($returnArr);
        $fileContent = json_encode($returnArr);
$dir = "soapGetDate/";
\Org\Util\File::createDir($dir);
file_put_contents($dir . $Flag . "_qq123.txt", $fileContent);
//dump($fileContent);
        echo json_encode($returnArr);
    }


    /*
    **数组去重
    **2017-06-27  by jack add
    */
    function more_array_unique($arr=array()){  
        foreach($arr[0] as $k => $v){  
            $arr_inner_key[]= $k;   //先把二维数组中的内层数组的键值记录在在一维数组中  
        }  
        foreach ($arr as $k => $v){  
            $v =join(",",$v);    //降维 用implode()也行  
            $temp[$k] =$v;      //保留原来的键值 $temp[]即为不保留原来键值  
        }  
        $temp =array_unique($temp);    //去重：去掉重复的字符串  
        foreach ($temp as $k => $v){  
            $a = explode(",",$v);   //拆分后的重组 如：Array( [0] => james [1] => 30 )  
            $arr_after[$k]= array_combine($arr_inner_key,$a);  //将原来的键与值重新合并  
        }  
        return $arr_after;  
    }
    /**
     *获取排班分时
     * @param $hospitalId '院区ID'
     * @param $requestid '厂商ID'
     * @param  $scheduleid 排班id
     */
    function registTimePointList()
    {
        $hospitalId = $_POST['districtCode'];//院区ID
        $scheduleid = $_POST['RBASId']; //排班ID

        /*$hospitalId= '1002';    
        $scheduleid = '70451';*/

        //$client = new \SOAPClient(C('URL_API'));
        $client = new \SOAPClient('http://192.168.100.149:9192/OrderTreat/services/HosiptalManager?wsdl');//测试地址
        $xml=$this->get_GetSchedulePartTime_xml(C('requestId'),$hospitalId,$scheduleid);
       //dump($xml);die();
        $function="GetSchedulePartTime";
        $result_doclist=$this->Get_service_api($xml,$client,$function);

        if($result_doclist['returncode']!='1'){
            $returnArr['status'] = 2;
            $returnArr['errorMsg'] = isset($result_doclist['returncode'])?$result_doclist['returncode']:"访问异常！code:201";
            echo json_encode($returnArr);exit;
        }else{//格式化为标准接口模式

            $ywsz_jj=$result_doclist['data'];      
            if (count($ywsz_jj) == count($ywsz_jj, 1)) {
                //echo '是一维数组';
                $newData[]=array(
                        'periodid'=>$ywsz_jj['parttimeid'],         //分时ID
                        'RBASId'=>$ywsz_jj['scheduleid'],         //排班ID
                        'districtCode'=>$ywsz_jj['hospitalid'], 
                        'starttime'=>$ywsz_jj['starttime'],           //开始时间
                        'endtime'=>$ywsz_jj['endtime'],               //结束时间
                        'regflag'=>$ywsz_jj['regflag'],               //挂号状态 Int  1可挂 -1不可挂    
                    ); 
            } else {
                //$result_doclist['data']=$ywsz_jj;
            

                foreach ($result_doclist['data'] as $k=>$v){
                     $newData[]=array(
                            'periodid'=>$v['parttimeid'],         //分时ID
                            'RBASId'=>$v['scheduleid'],         //排班ID
                            'districtCode'=>$v['hospitalid'], 
                            'starttime'=>$v['starttime'],           //开始时间
                            'endtime'=>$v['endtime'],               //结束时间
                            'regflag'=>$v['regflag'],               //挂号状态 Int  1可挂 -1不可挂    
                        ); 
                }
            };
        }
        $returnArr['data']['duty'] = $newData;
        //dump($result_doclist);
        echo json_encode($returnArr);
    }

     /**
     * 统一调接口方法
     * $xml       接口传递的参数
     * $client    接口需要调用的webservice对象
     * $function  接口的方法名
     * */
    function Get_service_api($xml,$client,$function){
        

        $xml=base64_encode($xml);
        $xml=array('inputxml'=>$xml);
        $result=$client->$function($xml);
        $hospital_info=$this->xml_to_array(base64_decode($result->out));
        
        //dump($hospital_info);
        $res=$hospital_info['data']['data_row'];
        $res1=$hospital_info['outputvalues']; //锁号的输出参数格式
        $aa['returncode']=$hospital_info['returnresult']['returncode'];
        $aa['errormsg']=$hospital_info['returnresult']['errormsg'];
        $aa['rowcountall']=$hospital_info['pageactionout']['rowcountall'];//获取总行数
        if($res){
            if ($function=='GetScheduleList') {
                if($hospital_info['pageactionout']['rowcountall']=='1'){
                    $aa['data'][0]['scheduleid']=$hospital_info['data']['data_row']['scheduleid'];
                    $aa['data'][0]['hospitalid']=$hospital_info['data']['data_row']['hospitalid'];
                    $aa['data'][0]['hospitalname']=$hospital_info['data']['data_row']['hospitalname'];
                    $aa['data'][0]['outpdate']=$hospital_info['data']['data_row']['outpdate'];
                    $aa['data'][0]['timeinterval']=$hospital_info['data']['data_row']['timeinterval'];
                    $aa['data'][0]['deptcode']=$hospital_info['data']['data_row']['deptcode'];
                    $aa['data'][0]['deptname']=$hospital_info['data']['data_row']['deptname'];
                    $aa['data'][0]['doctorno']=$hospital_info['data']['data_row']['doctorno'];
                    $aa['data'][0]['doctorname']=$hospital_info['data']['data_row']['doctorname'];
                    $aa['data'][0]['doctortitle']=$hospital_info['data']['data_row']['doctortitle'];
                    $aa['data'][0]['outptypename']=$hospital_info['data']['data_row']['outptypename'];
                    $aa['data'][0]['clinicfee']=$hospital_info['data']['data_row']['clinicfee'];
                    $aa['data'][0]['registrationfee']=$hospital_info['data']['data_row']['registrationfee'];
                    $aa['data'][0]['reserveflag']=$hospital_info['data']['data_row']['reserveflag'];
                    $aa['data'][0]['schedulelist']=$hospital_info['data']['data_row']['schedulelist'];
                } else{
                    foreach ($res as $k=>$v){
                        $aa['data'][$k]['scheduleid']=$hospital_info['data']['data_row'][$k]['scheduleid'];
                        $aa['data'][$k]['hospitalid']=$hospital_info['data']['data_row'][$k]['hospitalid'];
                        $aa['data'][$k]['hospitalname']=$hospital_info['data']['data_row'][$k]['hospitalname'];
                        $aa['data'][$k]['outpdate']=$hospital_info['data']['data_row'][$k]['outpdate'];
                        $aa['data'][$k]['timeinterval']=$hospital_info['data']['data_row'][$k]['timeinterval'];
                        $aa['data'][$k]['deptcode']=$hospital_info['data']['data_row'][$k]['deptcode'];
                        $aa['data'][$k]['deptname']=$hospital_info['data']['data_row'][$k]['deptname'];
                        $aa['data'][$k]['doctorno']=$hospital_info['data']['data_row'][$k]['doctorno'];
                        $aa['data'][$k]['doctorname']=$hospital_info['data']['data_row'][$k]['doctorname'];
                        $aa['data'][$k]['doctortitle']=$hospital_info['data']['data_row'][$k]['doctortitle'];
                        $aa['data'][$k]['outptypename']=$hospital_info['data']['data_row'][$k]['outptypename'];
                        $aa['data'][$k]['clinicfee']=$hospital_info['data']['data_row'][$k]['clinicfee'];
                        $aa['data'][$k]['registrationfee']=$hospital_info['data']['data_row'][$k]['registrationfee'];
                        $aa['data'][$k]['reserveflag']=$hospital_info['data']['data_row'][$k]['reserveflag'];
                        $aa['data'][$k]['schedulelist']=$hospital_info['data']['data_row'][$k]['schedulelist'];
                    }
                }
            } else {
                $aa['data']=$res;
            }
        } else if($res1){
            $aa['data']=$res1;
        };
        return $aa;
    }

    /**
     * 统一调接口方法 绑卡
     * $xml       接口传递的参数
     * $client    接口需要调用的webservice对象
     * $function  接口的方法名
     * */
    function Get_service_api_card($xml,$client,$function){
        $xml=base64_encode($xml);
        $xml=array('inputxml'=>$xml);
        $result=$client->$function($xml);
        $hospital_info=$this->xml_to_array(base64_decode($result->out));
        //dump($hospital_info);die();
        $res=$hospital_info['patientInfos']['patientinfo'];
        $aa['returncode']=$hospital_info['returnresult']['returncode'];
        $aa['errormsg']=$hospital_info['returnresult']['errormsg'];
        if($res){
            $aa['patientInfos']=$res;
        }
        return $aa;
    }

    function Get_service_api_xincard($xml,$client,$function){
        $xml=base64_encode($xml);
        $xml=array('inputxml'=>$xml);
        $result=$client->$function($xml);
        $hospital_info=$this->xml_to_array(base64_decode($result->out));
        //dump($hospital_info);
        $resqq['status']=$hospital_info['returnresult']['returncode'];
        $resqq['errormsg']=$hospital_info['returnresult']['errormsg'];
        $res['data']=$hospital_info['patientInfos']['patientinfo']['cardInfos']['cardinfo'];
        $xin=$hospital_info['patientInfos']['patientinfo'];
        //dump($res);die();
        if($xin['cardInfos']['cardinfo']['patientId']){
            //echo 66;die();
            $resqq['data'][0]=$res['data'];
            $resqq['data'][0]['sheng']=$xin['patientIdcard'];
            $resqq['data'][0]['sex']=$xin['patientSex'];
            $resqq['data'][0]['birth']=$xin['bornDay'];
            $resqq['data'][0]['phone']=$xin['patientPhone'];
            $resqq['data'][0]['dizi']=$xin['homeAddress'];
            $resqq['data'][0]['name']=$xin['patientName'];
        }else{
            foreach ($res['data'] as $k => $v) {
                $resqq['data'][$k]=$v;
                $resqq['data'][$k]['sheng']=$xin['patientIdcard'];
                $resqq['data'][$k]['sex']=$xin['patientSex'];
                $resqq['data'][$k]['birth']=$xin['bornDay'];
                $resqq['data'][$k]['phone']=$xin['patientPhone'][0];
                $resqq['data'][$k]['dizi']=$xin['homeAddress'][0];
                $resqq['data'][$k]['name']=$xin['patientName'];
            }
        }
        //dump($resqq);die();
        return $resqq;
    }

    /**
     *无卡用户注册建档
     * @param $identyId '身份证号码'
     * @param $requestid '厂商ID'
     * @param  $patientname 姓名
     */
    function userRegister()
    {
        //$hospitalId= '1002';  
        
        /*$identyId = '42010019841123411X';// 
        $name = '麴修军ee6'; //廖佳一
        $sex = '1';
        $dob = '1988-04-14';
        $familyaddress = '武汉';
        $mobile = '13670076316';*/
        
        
        $identyId = $_POST['identyId']; //身份证号码
        $name = $_POST['name']; //姓名
        $sex = $_POST['sex']; //性别  1男2女9未知
        $dob = $_POST['BirthDate']; //出生年月
        $familyaddress = $_POST['Address']; //地址
        $mobile = $_POST['phone']; //手机号码
        

        
        //$client = new \SOAPClient(C('CARD_URL_API'));
        $client = new \SOAPClient('http://59.175.191.226:9192/OnlineManager/services/RegisterUserManager?wsdl');//测试地址
        $xml=$this->get_userRegister_xml(C('requestId'),$identyId,$name,$sex,$dob,$familyaddress,$mobile);
        $function="AddPatientAndCard";
        $result_list=$this->Get_service_api_card($xml,$client,$function);
        //dump($result_list);die();
        if($result_list['returncode']!='1'){
            $returnArr['status'] = 2;
            $returnArr['errorMsg'] = $result_list['errormsg'];
            //echo json_encode($returnArr);exit;
        }else{//格式化为标准接口模式
            $returnArr['status'] = 1;
            $returnArr['errorMsg']=$result_list['errormsg'];
            $ywsz_jj=$result_list['patientInfos']; 
            $newData=array(
                        'patientId'=>$ywsz_jj['patientId'],                 //HIS患者ID
                        'patientIdcard'=>$ywsz_jj['patientIdcard']         //ID卡号   
                    ); 
        }
        $returnArr['data'] = $newData;
        echo json_encode($returnArr);
    }

    /**
     *绑卡信息验证
     * @param $idcard '身份证号码'
     * @param $requestid '厂商ID'
     * @param  $patientname 姓名
     */
    function cardBindVerify()
    {   
        $identyId = $_POST['identyId']; //身份证号码 
        //$identyId = '429006198310251210';
        // 420102198406302010  42010219420103312x
        //$identyId = '429005200008280081';   
        //$client = new \SOAPClient(C('CARD_URL_API'));
        $client = new \SOAPClient('http://59.175.191.226:9192/OnlineManager/services/RegisterUserManager?wsdl');//测试地址
        $xml=$this->get_cardBindVerify_xml(C('requestId'),$identyId,$patientname);
        $function="GetPatientAndCardByIdCard";
        $result_list=$this->Get_service_api_card($xml,$client,$function);
        //dump($result_list);die;
        if($result_list['returncode']!='1'){
            $returnArr['status'] = 2;
            $returnArr['errorMsg'] = '失败！';
            //echo json_encode($returnArr);exit;
        }else{//格式化为标准接口模式
            $returnArr['status'] = 1;
            $returnArr['errorMsg']='成功!';
            $te_arry=$result_list['patientInfos']['patientId'];
            $tt_data=$result_list['patientInfos']; 
            $ywsz_jj1=$result_list['patientInfos']['cardInfos']['cardinfo'];
            if ($te_arry) {
                //echo '是一维数组';
                $tt_data1=$result_list["patientInfos"]["cardInfos"]["cardinfo"];
                $te_arry1=$tt_data["cardInfos"]["cardinfo"]["patientId"];
                 if ($te_arry1){
                    //echo '1是一维111';
                    $returnArr['data'][0]['patientName']=$tt_data['patientName'];  //姓名
                    $returnArr['data'][0]['patientId']=$tt_data['patientId'];      //HIS患者ID
                    $returnArr['data'][0]['patientIdcard']=$tt_data['patientIdcard'];  //身份证号
                    $returnArr['data'][0]['patientSex']=$tt_data['patientSex'];    //性别 1男 2女 9未知
                    $returnArr['data'][0]['BirthDate']=$tt_data['bornDay'];        //出生日期
                    $returnArr['data'][0]['mobile']=$tt_data['patientPhone'];      //手机号码
                    $returnArr['data'][0]['Address']=$tt_data['homeAddress'];      //地址

                    $returnArr['data'][0]['cardNo']=$tt_data1['cardNo'];   //卡号
                    $returnArr['data'][0]['cardType']=$tt_data1['cardType'];   //卡类型（1诊疗卡 2ID卡 4医保卡） 
                    $returnArr['data'][0]['balance']=$tt_data1['balance'];   //卡余额
                    $returnArr['data'][0]['patientNo']=$tt_data1['patientNo'];   //患者编号
                    $returnArr['data'][0]['createTime']=$tt_data1['createTime'];   //卡创建时间
                    $returnArr['data'][0]['status']=$tt_data1['status'];   //状态（0正常，1作废，2挂失。4冻结）
                 } else{
                    //echo '1是一维222';
                    foreach ($tt_data1 as $k => $v) {
                        $returnArr['data'][$k]['patientName']=$tt_data['patientName'];  //姓名
                        $returnArr['data'][$k]['patientId']=$tt_data['patientId'];      //HIS患者ID
                        $returnArr['data'][$k]['patientIdcard']=$tt_data['patientIdcard'];  //身份证号
                        $returnArr['data'][$k]['patientSex']=$tt_data['patientSex'];    //性别 1男 2女 9未知
                        $returnArr['data'][$k]['BirthDate']=$tt_data['bornDay'];        //出生日期
                        $returnArr['data'][$k]['mobile']=$tt_data['patientPhone'];      //手机号码
                        $returnArr['data'][$k]['Address']=$tt_data['homeAddress'];      //地址

                        $returnArr['data'][$k]['cardNo']=$tt_data1[$k]['cardNo'];   //卡号
                        $returnArr['data'][$k]['cardType']=$tt_data1[$k]['cardType'];   //卡类型（1诊疗卡 2ID卡 4医保卡） 
                        $returnArr['data'][$k]['balance']=$tt_data1[$k]['balance'];   //卡余额
                        $returnArr['data'][$k]['patientNo']=$tt_data1[$k]['patientNo'];   //患者编号
                        $returnArr['data'][$k]['createTime']=$tt_data1[$k]['createTime'];   //卡创建时间
                        $returnArr['data'][$k]['status']=$tt_data1[$k]['status'];   //状态（0正常，1作废，2挂失。4冻结）
                    }
                 }  ;
            } else {
                //echo '非一维数组';
                foreach ($tt_data as $k=>$v){
                    //echo '2';
                    if($tt_data[$k]['cardInfos']['cardinfo'])///取档案中有卡的数据
                    {   //$i=0;++$i;
                        //echo 'fenglaba'.$i;
                        $tt1_data1=$tt_data[$k]["cardInfos"]["cardinfo"];
                        $te_arry2=$tt_data[$k]['cardInfos']['cardinfo']['patientId'];
                         if ($te_arry2){
                            //echo '2是一维11';
                            $returnArr['data'][$k]['patientName']=$tt_data[$k]['patientName'];  //姓名
                            $returnArr['data'][$k]['patientId']=$tt_data[$k]['patientId'];      //HIS患者ID
                            $returnArr['data'][$k]['patientIdcard']=$tt_data[$k]['patientIdcard'];  //身份证号
                            $returnArr['data'][$k]['patientSex']=$tt_data[$k]['patientSex'];    //性别 1男 2女 9未知
                            $returnArr['data'][$k]['BirthDate']=$tt_data[$k]['bornDay'];        //出生日期
                            $returnArr['data'][$k]['mobile']=$tt_data[$k]['patientPhone'];      //手机号码
                            $returnArr['data'][$k]['Address']=$tt_data[$k]['homeAddress'];      //地址

                            $returnArr['data'][$k]['cardNo']=$tt1_data1['cardNo'];   //卡号
                            $returnArr['data'][$k]['cardType']=$tt1_data1['cardType'];   //卡类型（1诊疗卡 2ID卡 4医保卡） 
                            $returnArr['data'][$k]['balance']=$tt1_data1['balance'];   //卡余额
                            $returnArr['data'][$k]['patientNo']=$tt1_data1['patientNo'];   //患者编号
                            $returnArr['data'][$k]['createTime']=$tt1_data1['createTime'];   //卡创建时间
                            $returnArr['data'][$k]['status']=$tt1_data1['status'];   //状态（0正常，1作废，2挂失。4冻结）
                         } else{
                            //echo '   2是一维22';
                            foreach ($tt1_data1 as $k1=>$v1){
                                //echo $k1;
                                $returnArr['data'][$k*100+$k1]['patientName']=$tt_data[$k]['patientName'];  //姓名
                                $returnArr['data'][$k*100+$k1]['patientId']=$tt_data[$k]['patientId'];      //HIS患者ID
                                $returnArr['data'][$k*100+$k1]['patientIdcard']=$tt_data[$k]['patientIdcard'];  //身份证号
                                $returnArr['data'][$k*100+$k1]['patientSex']=$tt_data[$k]['patientSex'];    //性别 1男 2女 9未知
                                $returnArr['data'][$k*100+$k1]['BirthDate']=$tt_data[$k]['bornDay'];        //出生日期
                                $returnArr['data'][$k*100+$k1]['mobile']=$tt_data[$k]['patientPhone'];      //手机号码
                                $returnArr['data'][$k*100+$k1]['Address']=$tt_data[$k]['homeAddress'];      //地址

                                $returnArr['data'][$k*100+$k1]['cardNo']=$tt1_data1[$k1]['cardNo'];   //卡号
                                $returnArr['data'][$k*100+$k1]['cardType']=$tt1_data1[$k1]['cardType'];   //卡类型（1诊疗卡 2ID卡 4医保卡） 
                                $returnArr['data'][$k*100+$k1]['balance']=$tt1_data1[$k1]['balance'];   //卡余额
                                $returnArr['data'][$k*100+$k1]['patientNo']=$tt1_data1[$k1]['patientNo'];   //患者编号
                                $returnArr['data'][$k*100+$k1]['createTime']=$tt1_data1[$k1]['createTime'];   //卡创建时间
                                $returnArr['data'][$k*100+$k1]['status']=$tt1_data1[$k1]['status'];   //状态（0正常，1作废，2挂失。4冻结）

                            }
                         }  
                    }

                }
            }

        };
        //dump($returnArr);die();
        $result=$returnArr;
        $result['data']=array_values($result['data']);
        foreach ( $result['data'] as $key => $row ){
            $num1[$key] = $row ['cardType'];
            $num2[$key] = $row ['createTime'];
        }
        array_multisort($num1, SORT_DESC, $num2, SORT_DESC, $result['data']);
        //就诊卡(卡类型=1)如果有多张就只取最近的一张(创建时间最新的)
        $i=0;
        foreach ($result['data'] as $k => $v) {
            if($v['cardType']==1){
                $i+=1;
            }
            if($i==2){
                unset($result['data'][$k]);
            }
        }
        $result['data']=array_values($result['data']);
        //dump($result);
        foreach ($result['data'] as $k => $v) {
            $result['data'][$k]['name']=$v['patientName'];
            $result['data'][$k]['sheng']=$v['patientIdcard'];
            if($v['patientSex']==9){
                $v['patientSex']=0;
            }
            $result['data'][$k]['sex']=$v['patientSex'];
            if(is_array($v['mobile'])){
                $result['data'][$k]['phone']=!empty($v['mobile'][0])?$v['mobile'][0]:'';
            } else {  
                $result['data'][$k]['phone']=!empty($v['mobile'])?$v['mobile']:'';;
            }
            if(is_array($v['Address'])){
                $result['data'][$k]['dizi']=!empty($v['Address'][0])?$v['Address'][0]:'';
            } else {  
                $result['data'][$k]['dizi']=!empty($v['Address'])?$v['Address']:'';;
            }
            $result['data'][$k]['birth']=$v['BirthDate'];
            $result['data'][$k]['modifyTime']=$v['createTime'];
            /*unset($result['data'][$k]['patientName']);
            unset($result['data'][$k]['patientIdcard']);
            unset($result['data'][$k]['patientSex']);
            unset($result['data'][$k]['Address']);
            unset($result['data'][$k]['mobile']);
            unset($result['data'][$k]['BirthDate']);*/
        }
        //var_dump($result);
        echo json_encode($result,true);
    }

    /**
     *修改手机号
     * @param $requestid '厂商ID'
     */
    function EditPatientBase()
    {
        $fileContent = '66666';
$dir = "soapGetDate/";
\Org\Util\File::createDir($dir);
file_put_contents($dir . $Flag . "_aa.txt", $fileContent);

        $patientid = $_POST['patientid']; //病人ID
        $pname = $_POST['pname'];   //姓名
        $sex = $_POST['sex'];       //性别
        $dob = $_POST['dob'];       //出生日期
        $idcode = $_POST['idcode']; //身份证号码
        $mobile = $_POST['mobile']; //手机号码
        $client = new \SOAPClient(C('CARD_URL_API'));
        $xml=$this->get_EditPatientBase_xml(C('requestId'),$patientid,$pname,$sex,$dob,$idcode,$mobile);
        //dump($xml);

        $fileContent = $xml;
$dir = "soapGetDate/";
\Org\Util\File::createDir($dir);
file_put_contents($dir . $Flag . "_bb.txt", $fileContent);

        $function="EditPatientBase";
        $result_list=$this->Get_service_api_card($xml,$client,$function);
        //dump($result_list);
        if($result_list['returncode']!='1'){
            $returnArr['status'] = 2;
            $returnArr['errorMsg'] = $result_list['errormsg'];
            //echo json_encode($returnArr);exit;
        }else{//格式化为标准接口模式
            $returnArr['status'] = 1;
            $returnArr['errorMsg']='成功!';
        };
        //dump($returnArr);
        echo json_encode($returnArr);
    }

    /**
     *新建订单锁号
     * @param $requestid '厂商ID'
     * @param  $patientname 姓名
     */
    function registration($reservemobile,$districtCode,$scheduleid,$parttimeid,$certtypeno,$patientidcard,$patientname,$patientsex,$patientbirthday,$medicalrecord,$contactphone,$familyaddress,$payregfee)
    {
        $hospitalId=$districtCode;
        //echo $reservemobile.'+'.$hospitalId.'+'.$scheduleid.'+'.$parttimeid.'+'.$certtypeno.'+'.$patientidcard.'+'.$patientname.'+'.$patientsex.'+'.$patientbirthday.'+'.$medicalrecord.'+'.$contactphone.'+'.$familyaddress.'+'.$payregfee;die();
        /*$reservemobile= '13670076316';     //手机号码
        $hospitalId= '1002';        //院区ID
        $scheduleid= '70458';        //日排班ID
        $parttimeid= '269639';        //分时ID
        $certtypeno= '1';        //证件类型  1身份证 2军官证 3警官证 4文职干部证 5士兵证 6户口簿 7护照 8港澳台同胞回乡证 9营业执照号
        $patientidcard= '420100198804143155';     //证件号
        $patientname = '何黎';        //姓名
        $patientsex = '男';         //患者性别  男 女
        $patientbirthday = '1988-04-14';    //出生日期
        $medicalrecord = '027123';      //病历号
        $contactphone = '13670076316';       //联系电话
        $familyaddress = '201705020059|2|武汉';      //病人id|卡类型（传“2”）|家庭地址@时点ID
        $payregfee = '1';          //联系电话 是否需要扣费 1：扣费 0：不扣费*/

        //$client = new \SOAPClient(C('URL_API'));
        $client = new \SOAPClient('http://192.168.100.149:9192/OrderTreat/services/HosiptalManager?wsdl');//测试地址
        $xml=$this->get_registration_xml(C('requestId'),$reservemobile,$hospitalId,$scheduleid,$parttimeid,$certtypeno,$patientidcard,$patientname,$patientsex,$patientbirthday,$medicalrecord,$contactphone,$familyaddress,$payregfee);

         $fileContent = $xml;
$dir = "soapGetDate/";
\Org\Util\File::createDir($dir);
file_put_contents($dir . $Flag . "_qq_wxb.txt", $fileContent);

        $function="NewOrderAll";
        $result_list=$this->Get_service_api($xml,$client,$function);

         $fileContent = $result_list;
$dir = "soapGetDate/";
\Org\Util\File::createDir($dir);
file_put_contents($dir . $Flag . "_qq_wxb2.txt", $fileContent);

        //dump($result_list);
        if($result_list['returncode']!='1'){
            $returnArr['status'] = 2;
            $returnArr['errorMsg'] = $result_list['errormsg'];
            //echo json_encode($returnArr);exit;
        }else{//格式化为标准接口模式
            $returnArr['status'] = 1;
            $returnArr['errorMsg']=$result_list['errormsg'];
            $ywsz_jj=$result_list['data'];  
            $newData=array(
                        'orderid'=>$ywsz_jj['orderid'],         //订单号
                        'reservefee'=>$ywsz_jj['reservefee'],   //预约费  
                        'clinicfee'=>$ywsz_jj['clinicfee'],     //诊疗费
                        'registrationfee'=>$ywsz_jj['registrationfee'],    //挂号费
                        'pinkey'=>$ywsz_jj['pinkey'],           //数字订单号
                        'ordertime'=>$ywsz_jj['ordertime'],     //订单生成时间
                        'payregfee'=>$ywsz_jj['payregfee']     //是否需要扣费
                    ); 
        }
        $returnArr['data'] = $newData;
        echo json_encode($returnArr);
    }


/**
     * 新建订单锁号
     * $xml       接口传递的参数
     * */
    function get_registration_xml($requestid,$reservemobile,$hospitalId,$scheduleid,$parttimeid,$certtypeno,$patientidcard,$patientname,$patientsex,$patientbirthday,$medicalrecord,$contactphone,$familyaddress,$payregfee){
        $xml="<?xml version='1.0' encoding='utf-8'?><request><requestid>".$requestid."</requestid><inputvalues><reservemobile>".$reservemobile."</reservemobile><hospitalid>".$hospitalId."</hospitalid><scheduleid>".$scheduleid."</scheduleid><parttimeid>".$parttimeid."</parttimeid><certtypeno>".$certtypeno."</certtypeno><patientidcard>".$patientidcard."</patientidcard><patientname>".$patientname."</patientname><patientsex>".$patientsex."</patientsex><patientbirthday>".$patientbirthday."</patientbirthday><medicalrecord>".$medicalrecord."</medicalrecord><contactphone>".$contactphone."</contactphone><familyaddress>".$familyaddress."</familyaddress><payregfee>".$payregfee."</payregfee><data><data_row><field_code></field_code><field_value></field_value></data_row></data></inputvalues></request>";
        return $xml;
    }

    public function xml_to_array($list){
        $ob= simplexml_load_string($list);
        $json  = json_encode($ob);
        $configData = json_decode($json, true);
        return $configData;
    }

    function get_GetDoctorSchedule_xml($requestid,$currentpagenum,$rowsperpage,$pageaction,$topagenum,$begindate,$hospitalid){
        $xml="<?xml version='1.0' encoding='utf-8'?><request><requestid>512</requestid><pageactionin><currentpagenum>1</currentpagenum><rowsperpage>20</rowsperpage><pageaction>firstpage</pageaction><topagenum>1</topagenum></pageactionin><retrieveargs><begindate></begindate><hospitalid>1001</hospitalid></retrieveargs></request>";
        return $xml;
    }

    function get_GetHospitalList_xml($requestid){
        $xml="<?xml version='1.0' encoding='utf-8'?><request><requestid>".$requestid."</requestid><pageactionin><currentpagenum>1</currentpagenum><rowsperpage>20</rowsperpage><pageaction>firstpage</pageaction><topagenum>1</topagenum></pageactionin><retrieveargs><begindate></begindate><hospitalid>1001</hospitalid></retrieveargs></request>";
        return $xml;
    }

    function get_hosInstitutionClass_xml($requestid,$hospitalId){
        $xml="<?xml version='1.0' encoding='utf-8'?><request><requestid>".$requestid."</requestid><pageactionin><currentpagenum></currentpagenum><rowsperpage>500</rowsperpage><pageaction>firstpage</pageaction><topagenum></topagenum></pageactionin><retrieveargs><begindate></begindate><hospitalid>".$hospitalId."</hospitalid><deptcode></deptcode></retrieveargs></request>";
        return $xml;
    }

    function get_dutyDoctor_xml($requestid,$hospitalId){
        $xml="<?xml version='1.0' encoding='utf-8'?><request><requestid>".$requestid."</requestid><pageactionin><currentpagenum></currentpagenum><rowsperpage>1000</rowsperpage><pageaction>firstpage</pageaction><topagenum></topagenum></pageactionin><retrieveargs><begindate></begindate><hospitalid>".$hospitalId."</hospitalid><doctorno></doctorno></retrieveargs></request>";
        return $xml;
    }

    function get_getDoctorSource_xml($requestid,$outpdate_start,$outpdate_end,$hospitalId,$deptHisId,$docHisId){
        $xml="<?xml version='1.0' encoding='utf-8'?><request><requestid>".$requestid."</requestid><pageactionin><currentpagenum></currentpagenum><rowsperpage>50</rowsperpage><pageaction>firstpage</pageaction><topagenum></topagenum></pageactionin><retrieveargs><outpdate_start>".$outpdate_start."</outpdate_start><outpdate_end>".$outpdate_end."</outpdate_end><timeinterval></timeinterval ><hospitalid>".$hospitalId."</hospitalid><deptcode>".$deptHisId."</deptcode><doctorno>".$docHisId."</doctorno><specialty></specialty></retrieveargs></request>";
        return $xml;
    }

    function get_GetSchedulePartTime_xml($requestid,$hospitalId,$scheduleid){
        $xml="<?xml version='1.0' encoding='utf-8'?><request><requestid>".$requestid."</requestid><retrieveargs><hospitalid>".$hospitalId."</hospitalid><scheduleid>".$scheduleid."</scheduleid></retrieveargs></request>";
        return $xml;
    }

    function get_userRegister_xml($requestid,$identyId,$name,$sex,$dob,$familyaddress,$mobile){
        $xml="<?xml version='1.0' encoding='utf-8'?><request><requestid>".$requestid."</requestid><retrieveargs><hospitalid>1000</hospitalid><cardtype>2</cardtype><cardno/><patientid/><name>".$name."</name><sex>".$sex."</sex><dob>".$dob."</dob><idcode>".$identyId."</idcode><idtype>10</idtype><familyaddress>".$familyaddress."</familyaddress><mobile>".$mobile."</mobile></retrieveargs></request>";
        return $xml;
    }

    function get_cardBindVerify_xml($requestid,$identyId,$patientname){
        $xml="<?xml version='1.0' encoding='utf-8'?><request><requestid>".$requestid."</requestid><retrieveargs><hospitalid>1000</hospitalid><patientname></patientname><idcard>".$identyId."</idcard></retrieveargs></request>";
        return $xml;
    }

    /**
     * 提交订单生效
     * $xml       接口传递的参数
     * */
    function get_ConfirmOrder_xml($requestid,$orderid,$paymentcode){
        $xml="<?xml version='1.0' encoding='utf-8'?><request><requestid>".$requestid."</requestid><inputvalues><orderid>".$orderid."</orderid><paymentcode>".$paymentcode."</paymentcode></inputvalues></request>";
        return $xml;
    }

    /**
     * 修改手机号码
     * $xml       接口传递的参数
     * */
    function get_EditPatientBase_xml($requestid,$patientid,$pname,$sex,$dob,$idcode,$mobile){
        $xml="<?xml version='1.0' encoding='utf-8'?><request><requestid>".$requestid."</requestid><retrieveargs><hospitalid>1000</hospitalid><cardtype></cardtype><cardno/><patientid>".$patientid."</patientid><name>".$pname."</name><sex>".$sex."</sex><dob>".$dob."</dob><idcode>".$idcode."</idcode><idtype>10</idtype><familyaddress></familyaddress><mobile>".$mobile."</mobile></retrieveargs></request>";
        return $xml;
    }

    /**
     *提交订单
     * @param $requestid '厂商ID'
     * @param  $orderid 姓名
     */
    function ConfirmOrder(){
        $orderid = $_POST['orderid'];
        $paymentcode= '01';//支付方式代码 00：不支付,01：支付
        //$orderid= '3960b5a9-2ac4-4fcd-9024-c3f3a66a7276';//订单号

        //$client = new \SOAPClient(C('URL_API'));
        $client = new \SOAPClient('http://192.168.100.149:9192/OrderTreat/services/HosiptalManager?wsdl');//测试地址
        $xml=$this->get_ConfirmOrder_xml(C('requestId'),$orderid,$paymentcode);
        $function="ConfirmOrder";
        $result_list=$this->Get_service_api($xml,$client,$function);
        //dump($result_list);

        if($result_list['returncode']!='1'){
            $returnArr['status'] = 2;
            $returnArr['errorMsg'] = $result_list['errormsg'];
            //echo json_encode($returnArr);exit;
        }else{//格式化为标准接口模式
            $returnArr['status'] = 1;
            $returnArr['errorMsg']=$result_list['errormsg'];
            $ywsz_jj=$result_list['data'];  
            $newData=array(
                        'orderconfirmsms'=>$ywsz_jj['orderconfirmsms'],//所挂编号
                        'serial'=>$ywsz_jj['serial'],//就诊序号  
                        'outptime'=>$ywsz_jj['outptime']//就诊时间
                    ); 
        }
        $returnArr['data']= $newData;
        echo json_encode($returnArr);

    }

    /**
     * 取历史挂号订单
     * */
    function get_GetOrderInfo_xml($requestid,$pinkey,$reservemobile,$patientname,$patientidcard,$creator,$orderstate){
        $xml="<?xml version='1.0' encoding='utf-8'?><request><requestid>".$requestid."</requestid><pageactionin><currentpagenum>1</currentpagenum><rowsperpage>50</rowsperpage><pageaction>firstpage</pageaction><topagenum>1</topagenum></pageactionin><inputvalues><pinkey>".$pinkey."</pinkey><reservemobile>".$reservemobile."</reservemobile><patientname>".$patientname."</patientname><patientidcard>".$patientidcard."</patientidcard><creator>".$creator."</creator><orderstate>".$orderstate."</orderstate></inputvalues></request>";
        return $xml;
    }

    /**
     *取历史挂号订单
     * @param $requestid '厂商ID'
     */
    function GetOrderInfo()
    {
        //数字订单号  如果放空则查询所有订单 1002201750600001
        $pinkey = '';
        //预约人手机号
        //$reservemobile = '13670076316';
        //就诊人姓名
        //$patientname = '何黎';
        //就诊人证件号
        //$patientidcard ='420100198804143155';
        //$creator ='';               //订单创建人
        //$orderstate ='';            //订单状态 订单状态取值 1：预约中2：预约成功（未报到）3：已报到4：作废订单（预定未成功）5:??退费中6：退订订单（退费的）

        $pinkey = $_POST['pinkey'];
        $reservemobile = $_POST['reservemobile'];
        $patientname = $_POST['patientname'];
        $patientidcard = $_POST['patientidcard'];
        $creator = $_POST['creator'];
        $orderstate = $_POST['orderstate'];
        //$client = new \SOAPClient(C('URL_API'));
        $client = new \SOAPClient('http://192.168.100.149:9192/OrderTreat/services/HosiptalManager?wsdl');//测试地址
        $xml=$this->get_GetOrderInfo_xml(C('requestId'),$pinkey,$reservemobile,$patientname,$patientidcard,$creator,$orderstate);
        //dump($xml);
        $fileContent = $xml;
$dir = "soapGetDate/";
\Org\Util\File::createDir($dir);
file_put_contents($dir . $Flag . "_qq_wxb.txt", $fileContent);


        $function="GetOrderInfo";
        $result_list=$this->Get_service_api($xml,$client,$function);

        //dump($result_list);
        $fileContent = $function."+".$result_list;
$dir = "soapGetDate/";
\Org\Util\File::createDir($dir);
file_put_contents($dir . $Flag . "_qq_wxb2.txt", $fileContent);

        if($result_list['returncode']!='1'){
            $returnArr['status'] = 2;
            $returnArr['errorMsg'] = $result_list['errormsg'];
            //echo json_encode($returnArr);exit;
        }else{//格式化为标准接口模式
            $returnArr['status'] = 1;
            $returnArr['errorMsg']=$result_list['errormsg'];
            $ywsz_jj=$result_list['data']; 
            $row_count=$result_list['rowcountall']; 
            if ($row_count == '1') {
                $newData[]=array(
                        'orderid'=>$ywsz_jj['orderid'],             //订单ID
                        'reservetime'=>$ywsz_jj['reservetime'],     //预约开始时间  
                        'pinkey'=>$ywsz_jj['pinkey'],        //数字订单号
                        'resourcemobile'=>$ywsz_jj['resourcemobile'], //预约电话
                        'scheduleid'=>$ywsz_jj['scheduleid'],   //日排班id
                        'hospitalid'=>$ywsz_jj['hospitalid'],   //医院代码
                        'hospitalname'=>$ywsz_jj['hospitalname'],   //医院名称
                        'outpdate'=>$ywsz_jj['outpdate'],           //出诊日期
                        'timeinterval'=>$ywsz_jj['timeinterval'],   //时间段
                        'clinictypename'=>$ywsz_jj['clinictypename'],       //门诊类别
                        'deptcode'=>$ywsz_jj['deptcode'],           //科室代码
                        'deptname'=>$ywsz_jj['deptname'],           //科室名称
                        'doctorno'=>$ywsz_jj['doctorno'],           //医生编号
                        'doctorname'=>$ywsz_jj['doctorname'],       //医生姓名
                        'doctortitle'=>$ywsz_jj['doctortitle'],     //医生职称
                        'clinicfee'=>$ywsz_jj['clinicfee'],         //诊疗费
                        'registrationfee'=>$ywsz_jj['registrationfee'], //挂号费
                        'certtypeno'=>$ywsz_jj['certtypeno'],       //证件类型
                        'patientidcard'=>$ywsz_jj['patientidcard'], //证件号码
                        'patientname'=>$ywsz_jj['patientname'],     //姓名
                        'patientsex'=>$ywsz_jj['patientsex'],       //性别
                        'patientbirthday'=>$ywsz_jj['patientbirthday'], //出生日期
                        'medicalrecord'=>$ywsz_jj['medicalrecord'], //病历号
                        'contactphone'=>$ywsz_jj['contactphone'],   //联系电话   
                        'familyaddress'=>$ywsz_jj['familyaddress'], //家庭地址   
                        'paymentcode'=>$ywsz_jj['paymentcode'],     //支付方式
                        'orderstatus'=>$ywsz_jj['orderstatus'],     //订单状态int  1：预约中2：预约成功（未报到）3：已报到4：作废订单（预定未成功）5：退订订单
                        'reservesuccesstime'=>$ywsz_jj['reservesuccesstime'],   //预订成功时间
                        'checkintime'=>$ywsz_jj['checkintime'],     //报道时间
                        'cancelsource'=>$ywsz_jj['cancelsource'],   //退订来源
                        'canceltime'=>$ywsz_jj['canceltime'],       //退订时间
                        'cancelreason'=>$ywsz_jj['cancelreason'],   //退订原因
                        'backfeemoney'=>$ywsz_jj['backfeemoney'],   //退费金额
                        'backfeetime'=>$ywsz_jj['backfeetime'],     //退费时间
                        'comments'=>$ywsz_jj['comments'],           //订单备注
                        'isrefund'=>$ywsz_jj['isrefund'],           //能否退费 1：可以退费，其它值表示不能退费的理由
                        'isvalid'=>$ywsz_jj['isvalid']              //号源是否有效 -1：已停诊，0：未发布，其它数字均表示正常
                    ); 
            } else{
                foreach ($result_list['data'] as $k=>$v){
                $newData[$k]=array(
                        'orderid'=>$v['orderid'],             //订单ID
                        'reservetime'=>$v['reservetime'],     //预约开始时间  
                        'pinkey'=>$v['pinkey'],        //数字订单号
                        'resourcemobile'=>$v['resourcemobile'], //预约电话
                        'scheduleid'=>$v['scheduleid'],   //日排班id
                        'hospitalid'=>$v['hospitalid'],   //医院代码
                        'hospitalname'=>$v['hospitalname'],   //医院名称
                        'outpdate'=>$v['outpdate'],           //出诊日期
                        'timeinterval'=>$v['timeinterval'],   //时间段
                        'clinictypename'=>$v['clinictypename'],       //门诊类别
                        'deptcode'=>$v['deptcode'],           //科室代码
                        'deptname'=>$v['deptname'],           //科室名称
                        'doctorno'=>$v['doctorno'],           //医生编号
                        'doctorname'=>$v['doctorname'],       //医生姓名
                        'doctortitle'=>$v['doctortitle'],     //医生职称
                        'clinicfee'=>$v['clinicfee'],         //诊疗费
                        'registrationfee'=>$v['registrationfee'], //挂号费
                        'certtypeno'=>$v['certtypeno'],       //证件类型
                        'patientidcard'=>$v['patientidcard'], //证件号码
                        'patientname'=>$v['patientname'],     //姓名
                        'patientsex'=>$v['patientsex'],       //性别
                        'patientbirthday'=>$v['patientbirthday'], //出生日期
                        'medicalrecord'=>$v['medicalrecord'], //病历号
                        'contactphone'=>$v['contactphone'],   //联系电话   
                        'familyaddress'=>$v['familyaddress'], //家庭地址   
                        'paymentcode'=>$v['paymentcode'],     //支付方式
                        'orderstatus'=>$v['orderstatus'],     //订单状态int  1：预约中2：预约成功（未报到）3：已报到4：作废订单（预定未成功）5：退订订单
                        'reservesuccesstime'=>$v['reservesuccesstime'],   //预订成功时间
                        'checkintime'=>$v['checkintime'],     //报道时间
                        'cancelsource'=>$v['cancelsource'],   //退订来源
                        'canceltime'=>$v['canceltime'],       //退订时间
                        'cancelreason'=>$v['cancelreason'],   //退订原因
                        'backfeemoney'=>$v['backfeemoney'],   //退费金额
                        'backfeetime'=>$v['backfeetime'],     //退费时间
                        'comments'=>$v['comments'],           //订单备注
                        'isrefund'=>$v['isrefund'],           //能否退费 1：可以退费，其它值表示不能退费的理由
                        'isvalid'=>$v['isvalid']              //号源是否有效 -1：已停诊，0：未发布，其它数字均表示正常
                    ); 
                }
            };
        }
        //dump($newData);
        $returnArr['data'] = $newData;
        echo json_encode($returnArr);
    }

    /**
     * 取消订单
     * */
    function get_CancelOrder_xml($requestid,$orderid,$pinkey,$cancelreason){
        $xml="<?xml version='1.0' encoding='utf-8'?><request><requestid>".$requestid."</requestid><inputvalues><orderid>".$orderid."</orderid><pinkey>".$pinkey."</pinkey><cancelreason>".$cancelreason."</cancelreason><operator></operator></inputvalues></request>";
        return $xml;
    }

    /**
     *取消订单   **在新建订单且没有提交订单之前可以取消订单
     * @param $requestid '厂商ID'
     * @param  $orderid 姓名
     */
    function CancelOrder(){
        //$orderid= '70d401b4-1117-42df-819f-e3e2cf0ce5b5';   //订单号
        //$pinkey= '1002201750400019';    //数字订单号

        $orderid = $_POST['orderid'];
        $pinkey = $_POST['pinkey']; 
        $cancelreason = $_POST['cancelreason'];

        //$client = new \SOAPClient(C('URL_API'));
        $client = new \SOAPClient('http://192.168.100.149:9192/OrderTreat/services/HosiptalManager?wsdl');//测试地址
        $xml=$this->get_CancelOrder_xml(C('requestId'),$orderid,$pinkey,$cancelreason);

        $function="CancelOrder";
        $result_list=$this->Get_service_api($xml,$client,$function);

        if($result_list['returncode']!='1'){
            $returnArr['status'] = 2;
            $returnArr['errorMsg'] = $result_list['errormsg'];
            //echo json_encode($returnArr);exit;
        }else{//格式化为标准接口模式
            $returnArr['status'] = 1;
            $returnArr['errorMsg']=$result_list['errormsg'];
        }
        //dump($returnArr);
        echo json_encode($returnArr);

    }

    /**
     *根据病人ID查询处方明细
     * @param  $patientId    '病人ID'
     */
     function prePayDoorList($patientId)
    {
        /*$res[0]['PresType']=1;
        $res[0]['PatientName']='姓名';
        $res[0]['PrescDate']='2017-05-20';
        $res[0]['OrderName']='项目名称';
        $res[0]['ActurlPrice']=5.00;
        $res[0]['Amount']=3;
        $res[0]['TotalMoney']=15.00;
        $res[0]['DoctorId']=59913;
        $res[0]['DoctorName']='';
        $res[0]['DeptId']='00010';
        $res[0]['DeptName']='看病科';
        $res[0]['AreaId']='1001';
        $aa['data']=$res;
        echo json_encode($aa);exit();*/
        //$patientId = '938559F7-6525-49D6-AE10-A5E90040C580';
        $soap = new \SoapClient(C('PAY_URL_API')); 
        //dump(C('PAY_URL_API'));die;

        $result = $soap->GetOutpatientPescriptionListByPatientId( 
                C('as_clientid'),C('as_logpwd'),$patientId
            );  
        $tesres = $this->xml_to_array($result);
        //dump($result);die();
        $te_arry=$tesres["RegisterList"]["Register"]["OutpatientPrescriptionlist"]["OutpatientPrescription"]["PrescriptionList"]["PrescriptionListItem"]["PrescriptionListId"];//判断是否二维数组
        if($tesres['code']!='200'){
            $returnArr['status'] = 2;
            $returnArr['errorMsg'] = $tesres['description'];
            //echo json_encode($returnArr);exit;
        }else{//格式化为标准接口模式
            $returnArr['status'] = 1;
            $returnArr['errorMsg'] = $tesres['description'];
            $res_data=$tesres["RegisterList"]["Register"]["OutpatientPrescriptionlist"]["OutpatientPrescription"];
            //$res_data12=$tesres["RegisterList"]["Register"]["OutpatientPrescriptionlist"]["OutpatientPrescription"];
            if($te_arry)
            {
                $res_cfmx=$res_data['PrescriptionList']["PrescriptionListItem"];
                $returnArr['data'][0]['PatientId']=$res_data['PatientId']; //病人ID
                $returnArr['data'][0]['PatientName']=$res_data['PatientName'];//病人姓名
                $returnArr['data'][0]['AreaId']=$res_data['AreaId'];   //院区ID
                $returnArr['data'][0]['RegisterId']=$res_data['RegisterId'];   //挂号ID
                $returnArr['data'][0]['CardId']=$res_data['CardId'];   //卡号ID
                $returnArr['data'][0]['PresType']=$res_data['PresType'];   //处方类型 1药品处方 2 检查治疗处方
                $returnArr['data'][0]['PrescriptionId']=$res_data['PrescriptionId'];//处方ID
                $returnArr['data'][0]['PrescDate']=$res_data['PrescDate']; //开方时间
                $returnArr['data'][0]['DeptId']=$res_data['DeptId'];
                $returnArr['data'][0]['DeptName']=$res_data['DeptName'][0];
                $returnArr['data'][0]['DoctorId']=$res_data['DoctorId'];
                $returnArr['data'][0]['DoctorName']=$res_data['DoctorName'][0];
                
                $returnArr['data'][0]['PrescriptionListId']=$res_cfmx['PrescriptionListId'];    //处方明细ID
                $returnArr['data'][0]['GroupId']=$res_cfmx['GroupId'];      //分组号
                $returnArr['data'][0]['SortNo']=$res_cfmx['SortNo'];        //排序号
                $returnArr['data'][0]['OrderName']=$res_cfmx['OrderName'];  //项目名称
                $returnArr['data'][0]['Amount']=$res_cfmx['Amount'];        //数量
                $returnArr['data'][0]['ActurlPrice']=$res_cfmx['ActurlPrice'];//价格
                $returnArr['data'][0]['TotalMoney']=$res_cfmx['TotalMoney'];    //金额

            } else {
                //dump($res_data);
                foreach ($res_data as $k => $v) {
                    $res_cfmx11=$res_data[$k]['PrescriptionList']["PrescriptionListItem"];
                    $res_cfmx22=$res_data[$k]["PrescriptionList"]["PrescriptionListItem"]["PrescriptionListId"];//判断是否二维数组2
                    $returnArr['data'][$k]['PatientId']=$res_data[$k]['PatientId']; //病人ID
                    $returnArr['data'][$k]['PatientName']=$res_data[$k]['PatientName'];//病人姓名
                    $returnArr['data'][$k]['AreaId']=$res_data[$k]['AreaId'];   //院区ID
                    $returnArr['data'][$k]['RegisterId']=$res_data[$k]['RegisterId'];   //挂号ID
                    $returnArr['data'][$k]['CardId']=$res_data[$k]['CardId'];   //卡号ID
                    $returnArr['data'][$k]['PresType']=$res_data[$k]['PresType'];   //处方类型 1药品处方 2 检查治疗处方
                    $returnArr['data'][$k]['PrescriptionId']=$res_data[$k]['PrescriptionId'];//处方ID
                    $returnArr['data'][$k]['PrescDate']=$res_data[$k]['PrescDate']; //开方时间
                    $returnArr['data'][$k]['DeptId']=$res_data[$k]['DeptId'];
                    $returnArr['data'][$k]['DeptName']=$res_data[$k]['DeptName'][0];
                    $returnArr['data'][$k]['DoctorId']=$res_data[$k]['DoctorId'];
                    $returnArr['data'][$k]['DoctorName']=$res_data[$k]['DoctorName'][0];
                    if($res_cfmx22)
                    {
                        //echo 11;
                        $returnArr['data'][$k]['PrescriptionList'][0]['PrescriptionListId']=$res_cfmx11['PrescriptionListId'];//处方明细ID
                        $returnArr['data'][$k]['PrescriptionList'][0]['GroupId']=$res_cfmx11['GroupId'];      //分组号
                        $returnArr['data'][$k]['PrescriptionList'][0]['SortNo']=$res_cfmx11['SortNo'];        //排序号
                        $returnArr['data'][$k]['PrescriptionList'][0]['OrderName']=$res_cfmx11['OrderName'];  //项目名称
                        $returnArr['data'][$k]['PrescriptionList'][0]['Amount']=$res_cfmx11['Amount'];        //数量
                        $returnArr['data'][$k]['PrescriptionList'][0]['ActurlPrice']=$res_cfmx11['ActurlPrice'];//价格
                        $returnArr['data'][$k]['PrescriptionList'][0]['TotalMoney']=$res_cfmx11['TotalMoney'];    //金额*
                    } else
                    {
                        //echo 222;
                        foreach ($res_cfmx11 as $k1 => $v1) {
                            $returnArr['data'][$k]['PrescriptionList'][$k1]['PrescriptionListId']=$res_cfmx11[$k1]['PrescriptionListId'];   //处方明细ID
                            $returnArr['data'][$k]['PrescriptionList'][$k1]['GroupId']=$res_cfmx11[$k1]['GroupId'];      //分组号
                            $returnArr['data'][$k]['PrescriptionList'][$k1]['SortNo']=$res_cfmx11[$k1]['SortNo'];        //排序号
                            $returnArr['data'][$k]['PrescriptionList'][$k1]['OrderName']=$res_cfmx11[$k1]['OrderName'];  //项目名称
                            $returnArr['data'][$k]['PrescriptionList'][$k1]['Amount']=$res_cfmx11[$k1]['Amount'];        //数量
                            $returnArr['data'][$k]['PrescriptionList'][$k1]['ActurlPrice']=$res_cfmx11[$k1]['ActurlPrice'];//价格
                            $returnArr['data'][$k]['PrescriptionList'][$k1]['TotalMoney']=$res_cfmx11[$k1]['TotalMoney'];    //金额
                        //echo 33;
                        }
                        //dump($res_cfmx11);
                    };
                }
            }           
        }
        foreach ($returnArr['data'] as $k => $v) {
            $price=0;
            foreach ($v['PrescriptionList'] as $k2 => $v2) {
                $price+=$v2['TotalMoney'];
            }
            $returnArr['data'][$k]['price']=$price;
        }
       //dump($returnArr);
        echo json_encode($returnArr);
    }

    /**
     *根据病人ID查询处方明细
     * @param  $patientId    '病人ID'
     */
     function prePayDoorLists($patientId)
    {
        /*$res[0]['PresType']=1;
        $res[0]['PatientName']='姓名';
        $res[0]['PrescDate']='2017-05-20';
        $res[0]['OrderName']='项目名称';
        $res[0]['ActurlPrice']=5.00;
        $res[0]['Amount']=3;
        $res[0]['TotalMoney']=15.00;
        $res[0]['DoctorId']=59913;
        $res[0]['DoctorName']='';
        $res[0]['DeptId']='00010';
        $res[0]['DeptName']='看病科';
        $res[0]['AreaId']='1001';
        $aa['data']=$res;
        echo json_encode($aa);exit();*/

        //$patientId = '938559F7-6525-49D6-AE10-A5E90040C580';
        $soap = new \SoapClient(C('PAY_URL_API')); 
        //dump(C('PAY_URL_API'));die;

        $result = $soap->GetOutpatientPescriptionListByPatientId( 
                C('as_clientid'),C('as_logpwd'),$patientId
            );  
        $tesres = $this->xml_to_array($result);
        //dump($result);die();
        $te_arry=$tesres["RegisterList"]["Register"]["OutpatientPrescriptionlist"]["OutpatientPrescription"]["PrescriptionList"]["PrescriptionListItem"]["PrescriptionListId"];//判断是否二维数组
        if($tesres['code']!='200'){
            $returnArr['status'] = 2;
            $returnArr['errorMsg'] = $tesres['description'];
            //echo json_encode($returnArr);exit;
        }else{//格式化为标准接口模式
            $returnArr['status'] = 1;
            $returnArr['errorMsg'] = $tesres['description'];
            $res_data=$tesres["RegisterList"]["Register"]["OutpatientPrescriptionlist"]["OutpatientPrescription"];
            //$res_data12=$tesres["RegisterList"]["Register"]["OutpatientPrescriptionlist"]["OutpatientPrescription"];
            if($te_arry)
            {
                $res_cfmx=$res_data['PrescriptionList']["PrescriptionListItem"];
                $returnArr['data'][0]['PatientId']=$res_data['PatientId']; //病人ID
                $returnArr['data'][0]['PatientName']=$res_data['PatientName'];//病人姓名
                $returnArr['data'][0]['AreaId']=$res_data['AreaId'];   //院区ID
                $returnArr['data'][0]['RegisterId']=$res_data['RegisterId'];   //挂号ID
                $returnArr['data'][0]['CardId']=$res_data['CardId'];   //卡号ID
                $returnArr['data'][0]['PresType']=$res_data['PresType'];   //处方类型 1药品处方 2 检查治疗处方
                $returnArr['data'][0]['PrescriptionId']=$res_data['PrescriptionId'];//处方ID
                $returnArr['data'][0]['PrescDate']=$res_data['PrescDate']; //开方时间
                $returnArr['data'][0]['DeptId']=$res_data['DeptId'];
                $returnArr['data'][0]['DeptName']=$res_data['DeptName'][0];
                $returnArr['data'][0]['DoctorId']=$res_data['DoctorId'];
                $returnArr['data'][0]['DoctorName']=$res_data['DoctorName'][0];
                
                $returnArr['data'][0]['PrescriptionListId']=$res_cfmx['PrescriptionListId'];    //处方明细ID
                $returnArr['data'][0]['GroupId']=$res_cfmx['GroupId'];      //分组号
                $returnArr['data'][0]['SortNo']=$res_cfmx['SortNo'];        //排序号
                $returnArr['data'][0]['OrderName']=$res_cfmx['OrderName'];  //项目名称
                $returnArr['data'][0]['Amount']=$res_cfmx['Amount'];        //数量
                $returnArr['data'][0]['ActurlPrice']=$res_cfmx['ActurlPrice'];//价格
                $returnArr['data'][0]['TotalMoney']=$res_cfmx['TotalMoney'];    //金额

            } else {
                //dump($res_data);
                foreach ($res_data as $k => $v) {
                    $res_cfmx11=$res_data[$k]['PrescriptionList']["PrescriptionListItem"];
                    $res_cfmx22=$res_data[$k]["PrescriptionList"]["PrescriptionListItem"]["PrescriptionListId"];//判断是否二维数组2
                    $returnArr['data'][$k]['PatientId']=$res_data[$k]['PatientId']; //病人ID
                    $returnArr['data'][$k]['PatientName']=$res_data[$k]['PatientName'];//病人姓名
                    $returnArr['data'][$k]['AreaId']=$res_data[$k]['AreaId'];   //院区ID
                    $returnArr['data'][$k]['RegisterId']=$res_data[$k]['RegisterId'];   //挂号ID
                    $returnArr['data'][$k]['CardId']=$res_data[$k]['CardId'];   //卡号ID
                    $returnArr['data'][$k]['PresType']=$res_data[$k]['PresType'];   //处方类型 1药品处方 2 检查治疗处方
                    $returnArr['data'][$k]['PrescriptionId']=$res_data[$k]['PrescriptionId'];//处方ID
                    $returnArr['data'][$k]['PrescDate']=$res_data[$k]['PrescDate']; //开方时间
                    $returnArr['data'][$k]['DeptId']=$res_data[$k]['DeptId'];
                    $returnArr['data'][$k]['DeptName']=$res_data[$k]['DeptName'][0];
                    $returnArr['data'][$k]['DoctorId']=$res_data[$k]['DoctorId'];
                    $returnArr['data'][$k]['DoctorName']=$res_data[$k]['DoctorName'][0];
                    if($res_cfmx22)
                    {
                        //echo 11;
                        $returnArr['data'][$k]['PrescriptionList'][0]['PrescriptionListId']=$res_cfmx11['PrescriptionListId'];//处方明细ID
                        $returnArr['data'][$k]['PrescriptionList'][0]['GroupId']=$res_cfmx11['GroupId'];      //分组号
                        $returnArr['data'][$k]['PrescriptionList'][0]['SortNo']=$res_cfmx11['SortNo'];        //排序号
                        $returnArr['data'][$k]['PrescriptionList'][0]['OrderName']=$res_cfmx11['OrderName'];  //项目名称
                        $returnArr['data'][$k]['PrescriptionList'][0]['Amount']=$res_cfmx11['Amount'];        //数量
                        $returnArr['data'][$k]['PrescriptionList'][0]['ActurlPrice']=$res_cfmx11['ActurlPrice'];//价格
                        $returnArr['data'][$k]['PrescriptionList'][0]['TotalMoney']=$res_cfmx11['TotalMoney'];    //金额*
                    } else
                    {
                        //echo 222;
                        foreach ($res_cfmx11 as $k1 => $v1) {
                            $returnArr['data'][$k]['PrescriptionList'][$k1]['PrescriptionListId']=$res_cfmx11[$k1]['PrescriptionListId'];   //处方明细ID
                            $returnArr['data'][$k]['PrescriptionList'][$k1]['GroupId']=$res_cfmx11[$k1]['GroupId'];      //分组号
                            $returnArr['data'][$k]['PrescriptionList'][$k1]['SortNo']=$res_cfmx11[$k1]['SortNo'];        //排序号
                            $returnArr['data'][$k]['PrescriptionList'][$k1]['OrderName']=$res_cfmx11[$k1]['OrderName'];  //项目名称
                            $returnArr['data'][$k]['PrescriptionList'][$k1]['Amount']=$res_cfmx11[$k1]['Amount'];        //数量
                            $returnArr['data'][$k]['PrescriptionList'][$k1]['ActurlPrice']=$res_cfmx11[$k1]['ActurlPrice'];//价格
                            $returnArr['data'][$k]['PrescriptionList'][$k1]['TotalMoney']=$res_cfmx11[$k1]['TotalMoney'];    //金额
                        //echo 33;
                        }
                        //dump($res_cfmx11);
                    };
                }
            }           
        }
        foreach ($returnArr['data'] as $k => $v) {
            $price=0;
            foreach ($v['PrescriptionList'] as $k2 => $v2) {
                $price+=$v2['TotalMoney'];
            }
            $returnArr['data'][$k]['price']=$price;
        }
       //dump($returnArr);
        echo json_encode($returnArr);
    }

    /**
     * 门诊缴费结算
     * */
    function get_GetprePayDocListSettlement_xml($HospitalId,$RegisterId,$datalist){
        $xml="<?xml version='1.0' encoding='utf-8'?><root><!--医院ID--><HospitalId>1000</HospitalId><!--院区ID--><AreaId>".$HospitalId."</AreaId><!--挂号ID--><RegisterId>".$RegisterId."</RegisterId><!--舍入位数（0不做处理，1：1位，2：2位）--><RoundNum>0</RoundNum><!--处方ID列表--><datalist>".$datalist."</datalist></root>";
        return $xml;
    }

    /**
     *门诊缴费结算
     * @param  $HospitalId    '院区'
     * @param  $RegisterId    '挂号ID'
     * @param  $datalist      '处方号' 多个处方时需叠加用,分开
     */
    function prePayDocListSettlement()
    {
        //$result['status']=1;
        //$result['data']['TotalCost']=500536;
        //$result['data']['outptime']=date('Y-m-d H:i:s',time());
        //echo json_encode($result);exit();

        $HospitalId = $_POST['districtCode']; //院区ID
        $RegisterId = $_POST['RegisterId'];
        $PrescriptionId = $_POST['PrescriptionId'];

        /*$HospitalId = '1001';//院区ID
        $RegisterId = '073f7cb3-64c4-43d2-976a-a77b00c21288';
        $PrescriptionId ='0ce5e16c-0cd9-4d84-bb2e-900b3b666505';*/

        $tarry = explode(",", $PrescriptionId);
        $t_datalist='';
        foreach ($tarry as $k => $v) {
           $t_datalist = $t_datalist.'<PrescriptionId>'.$tarry[$k].'</PrescriptionId>';
        };
        $xmlStrinArge =$this->get_GetprePayDocListSettlement_xml($HospitalId,$RegisterId,$t_datalist);

        $soap = new \SoapClient(C('PAY_URL_API')); 
        $result = $soap->ExpenseSettlement( 
                C('as_clientid'),C('as_logpwd'),$xmlStrinArge
            );  
        $tesres = $this->xml_to_array($result);
        if($tesres['code']!='200'){
            $returnArr['status'] = 2;
            $returnArr['errorMsg'] = $tesres['description'];
            //echo json_encode($returnArr);exit;
        }else{//格式化为标准接口模式
            $returnArr['status'] = 1;
            $returnArr['errorMsg'] = $tesres['description'];
            $returnArr['data']['TotalCost'] = $tesres['TotalCost']; //总金额
            $returnArr['data']['PreferenceMoney'] = $tesres['PreferenceMoney'];//优惠金额
            $returnArr['data']['MedicarePay'] = $tesres['MedicarePay'];//医保支付金额
            $returnArr['data']['PersonalPay'] = $tesres['PersonalPay'];//个人支付金额
            $returnArr['data']['SettlementId'] = $tesres['SettlementId'];//结算ID
            $returnArr['data']['InvoiceCount'] = $tesres['InvoiceCount'];//发票张数
        }
        //dump($returnArr);
        echo json_encode($returnArr);
    }

    /**
     * 门诊支付
     * */
    function get_UpdatePayInfo_xml($SettlementId,$Money,$ActualRecive,$TradeMoney,$SerialNo,$BusinessId){
        $xml="<?xml version='1.0' encoding='utf-8'?><root><!--结算ID--><SettlementId>".$SettlementId."</SettlementId><!--支付方式列表--><PayInfoList><!--支付方式--><PayInfo><!--支付方式ID--><PayTypeId>9</PayTypeId><!--支付方式名称--><PayTypeName>微信</PayTypeName><!--金额--><Money>".$Money."</Money><!--实收--><ActualRecive>".$ActualRecive."</ActualRecive><!--找零--><OddMoney></OddMoney><!--舍入--><Round></Round><!--交易金额--><TradeMoney>".$TradeMoney."</TradeMoney><!--交易流水号--><SerialNo>".$SerialNo."</SerialNo><!--原始结果--><OrginalResult></OrginalResult><!--卡号  ASCII   19  不足右补空格--><CardNo></CardNo><!-- 商户订单号（支付宝）--><BusinessId>".$BusinessId."</BusinessId><!--备用 ASCII   19  备用--><Reserve></Reserve><!-- 卡类型标志 ASCII   4   银行卡卡类--><CardType></CardType><!--卡名  ASCII   8   银行卡名称--><CardName></CardName><!--LRC    ASCII   3   三位数字，应该和请求一致--><LRC></LRC><!-- 商户号  ASCII   15  --><TradeCompany></TradeCompany><!--终端号 ASCII   8--><TerminalNo></TerminalNo><!--批次号    ASCII   6--><BatchNo></BatchNo><!--系统参考号    ASCII   12  --><ReferenceNo></ReferenceNo></PayInfo></PayInfoList></root>";
        return $xml;
    }

    /**
     *门诊支付 //武汉市中心医院用
     * @param  $SettlementId    '结算ID'
     * @param  $Money    '金额'
     * @param  $SerialNo  '交易流水号  厂商''
     * @param  $BusinessId '交易流水号  微信支付'    
     */
    function UpdatePayInfo($hospitalId,$SettlementId,$Money,$ActualRecive,$TradeMoney,$SerialNo,$BusinessId)
    {
        $SettlementId = $_POST['SettlementId']; //结算ID  
        $Money = $_POST['Money'];             //金额 
        $ActualRecive = $_POST['ActualRecive']; //实收 
        $TradeMoney = $_POST['TradeMoney'];   //交易金额 
        $SerialNo = $_POST['SerialNo'];       //交易流水号  厂商 
        $BusinessId = $_POST['BusinessId'];     //交易流水号  微信支付
        /*$SettlementId = 'ba031f22-0bf0-4990-a12b-9c488fc06120';//结算ID
        $Money = '25.00';        //金额
        $ActualRecive = '25.00'; //实收
        $TradeMoney = '25.00';   //交易金额
        $SerialNo = 'LSH201705240001';     //交易流水号  厂商
        $BusinessId = '4003702001201705242171499500';   //交易流水号  微信支付*/
        $xmlStrinArge =$this->get_UpdatePayInfo_xml($SettlementId,$Money,$ActualRecive,$TradeMoney,$SerialNo,$BusinessId);
        //dump($xmlStrinArge);die();
        $soap = new \SoapClient(C('PAY_URL_API')); 
        $result = $soap->UpdatePayInfo( 
                C('as_clientid'),C('as_logpwd'),$xmlStrinArge
            );  
        $tesres = $this->xml_to_array($result);
        if($tesres['code']!='200'){
            $returnArr['status'] = 2;
            $returnArr['errorMsg'] = $tesres['description'];
            //echo json_encode($returnArr);exit;
        }else{//格式化为标准接口模式
            $returnArr['status'] = 1;
            $returnArr['errorMsg'] = $tesres['description'];
            $returnArr['data']['RecordStatus'] = $tesres['RecordStatus']; //结算记录状态(0-正常,1-已退费，2-红冲,9-预算)
            $returnArr['data']['PayStatus'] = $tesres['PayStatus']; //支付状态(0-未支付 1-已支付)
            $returnArr['data']['InvoiceSerialNumber'] = $tesres['InvoiceSerialNumberList']['InvoiceSerialNumber']; //机制号（相当于发票号）
        }
        //dump($returnArr);
        echo json_encode($returnArr);
    }

    /**
     *依结算ID查询支付结果信息 //武汉市中心医院用
     * @param  $SettlementId    '结算ID'    
     */
    function GetPayInfoBySettlementId()
    {
        $SettlementId = $_POST['SettlementId']; //结算ID  
        //$SettlementId = '76636c91-3d1f-42b4-819a-c43086ccfbd4';//结算ID
        $soap = new \SoapClient(C('PAY_URL_API')); 
        $result = $soap->GetPayInfoBySettlementId( 
                C('as_clientid'),C('as_logpwd'),$SettlementId
            );  
        $tesres = $this->xml_to_array($result);
        $te_arry=$tesres["ExpensesList"]["Expenses"]["ExpensesId"];//判断是否二维数组
        if($tesres['code']!='200'){
            $returnArr['status'] = 2;
            $returnArr['errorMsg'] = $tesres['description'];
            //echo json_encode($returnArr);exit;
        }else{//格式化为标准接口模式
            $res_data=$tesres["ExpensesList"]["Expenses"];

            $returnArr['status'] = 1;
            $returnArr['errorMsg'] = $tesres['description'];
            $returnArr['data']['RecordStatus'] = $tesres['RecordStatus']; //结算记录状态(0-正常,1-已退费，2-红冲,9-预算)
            $returnArr['data']['PayStatus'] = $tesres['PayStatus']; //支付状态(0-未支付 1-已支付)
            $returnArr['data']['InvoiceSerialNumber'] = $tesres['InvoiceSerialNumberList']['InvoiceSerialNumber']; //机制号（相当于发票号）

            if($te_arry)
            {
                $returnArr['data']['ExpensesList'][0]['ExpensesId']=$res_data['ExpensesId'];//费用ID
                $returnArr['data']['ExpensesList'][0]['ExpensesType']=$res_data['ExpensesType'];//费别(1挂号，2收费)
                $returnArr['data']['ExpensesList'][0]['AreaId']=$res_data['AreaId'];//院区ID
                $returnArr['data']['ExpensesList'][0]['PatientId']=$res_data['PatientId'];//病人ID
                $returnArr['data']['ExpensesList'][0]['RegisterId']=$res_data['RegisterId'];//挂号ID
                $returnArr['data']['ExpensesList'][0]['OutpatientNo']=$res_data['OutpatientNo'];//门诊号
                $returnArr['data']['ExpensesList'][0]['PrescriptionId']=$res_data['PrescriptionId'];//处方ID
                $returnArr['data']['ExpensesList'][0]['RxListId']=$res_data['RxListId'];//处方明细ID
                $returnArr['data']['ExpensesList'][0]['ItemType']=$res_data['ItemType'];//项目类型(1-药品 2-项目)
                $returnArr['data']['ExpensesList'][0]['ItemName']=$res_data['ItemName'];//项目名称
                $returnArr['data']['ExpensesList'][0]['Specification']=$res_data['Specification'];//规格
                $returnArr['data']['ExpensesList'][0]['UnitName']=$res_data['UnitName'];//单位名称 盒，瓶
                $returnArr['data']['ExpensesList'][0]['Amount']=$res_data['Amount'];//数量
                $returnArr['data']['ExpensesList'][0]['ActualPrice']=$res_data['ActualPrice'];//价格
                $returnArr['data']['ExpensesList'][0]['ActualCost']=$res_data['ActualCost'];//金额
                $returnArr['data']['ExpensesList'][0]['SettlementId']=$res_data['SettlementId'];//结算ID
                $returnArr['data']['ExpensesList'][0]['ChargeDate']=$res_data['ChargeDate'];//收费日期
                $returnArr['data']['ExpensesList'][0]['CashierName']=$res_data['CashierName'];//收费员

            } else {
                foreach ($res_data as $k => $v) {
                    $returnArr['data']['ExpensesList'][$k]['ExpensesId']=$res_data[$k]['ExpensesId']; //费用id
                    $returnArr['data']['ExpensesList'][$k]['ExpensesType']=$res_data[$k]['ExpensesType'];//费别(1挂号，2收费)
                    $returnArr['data']['ExpensesList'][$k]['AreaId']=$res_data[$k]['AreaId'];//院区ID
                    $returnArr['data']['ExpensesList'][$k]['PatientId']=$res_data[$k]['PatientId'];//病人ID
                    $returnArr['data']['ExpensesList'][$k]['RegisterId']=$res_data[$k]['RegisterId'];//挂号ID
                    $returnArr['data']['ExpensesList'][$k]['OutpatientNo']=$res_data[$k]['OutpatientNo'];//门诊号
                    $returnArr['data']['ExpensesList'][$k]['PrescriptionId']=$res_data[$k]['PrescriptionId'];//处方ID
                    $returnArr['data']['ExpensesList'][$k]['RxListId']=$res_data[$k]['RxListId'];//处方明细ID
                    $returnArr['data']['ExpensesList'][$k]['ItemType']=$res_data[$k]['ItemType'];//项目类型(1-药品 2-项目)
                    $returnArr['data']['ExpensesList'][$k]['ItemName']=$res_data[$k]['ItemName'];//项目名称
                    $returnArr['data']['ExpensesList'][$k]['Specification']=$res_data[$k]['Specification'];//规格
                    $returnArr['data']['ExpensesList'][$k]['UnitName']=$res_data[$k]['UnitName'];//单位名称 盒，瓶
                    $returnArr['data']['ExpensesList'][$k]['Amount']=$res_data[$k]['Amount'];//数量
                    $returnArr['data']['ExpensesList'][$k]['ActualPrice']=$res_data[$k]['ActualPrice'];//价格
                    $returnArr['data']['ExpensesList'][$k]['ActualCost']=$res_data[$k]['ActualCost'];//金额
                    $returnArr['data']['ExpensesList'][$k]['SettlementId']=$res_data[$k]['SettlementId'];//结算ID
                    $returnArr['data']['ExpensesList'][$k]['ChargeDate']=$res_data[$k]['ChargeDate'];//收费日期
                    $returnArr['data']['ExpensesList'][$k]['CashierName']=$res_data[$k]['CashierName'];//收费员
                }
            }
        }
        dump($returnArr);
        echo json_encode($returnArr);
    }

    /**
     *根据住院号查询住院病人信息 //武汉市中心医院用
     * @param  $inPatientNo    '住院号'    
     */
    function getInPatientInfo($hospitalId,$inPatientNo,$organCode,$cardType,$CardNo)
    {
        //$inPatientNo = $_POST['inPatientNo']; //住院号 
        //$organCode = $_POST['organCode'];     //院区ID
        //$cardType = $_POST['cardType']; //卡类型 
        //$CardNo = $_POST['CardNo'];     //卡号
       /* $inPatientNo = '001000197';//住院号
        $organCode = 1001;        //院区ID int
        $cardType = 1;         //卡类型   int
        $CardNo = '';           //卡号*/
        //dump(C('INPATIENT_URL_API'));die;
        $soap = new \SoapClient(C('PAY_URL_API')); 
        $result = $soap->getInPatientInfo( 
                C('as_clientid'),C('as_logpwd'),$organCode,$inPatientNo,$cardType,$CardNo
            );  
         //dump(preg_replace('#<!--.*?-->#', '' , $result));die;
        $tesres_qbq = preg_replace('#<!--.*?-->#', '' , $result);//去掉标签注释
        $tesres = $this->xml_to_array($tesres_qbq);
        if($tesres['code']=='201'||$tesres['code']=='200'){
            $returnArr['status'] = 1; //返回成功 
            $returnArr['errorMsg'] = $tesres['description'];//201 表示住院病人信息有，但是没有预交金记录
            $returnArr['data']['InpatientId'] = $tesres['InPatientInfo']['InpatientId'];//住院ID（入院）
            $returnArr['data']['PatientId'] = $tesres['InPatientInfo']['PatientId']; //病人ID（入院）
            $returnArr['data']['InpatientNo'] = $tesres['InPatientInfo']['InpatientNo'];//住院号（入院）
            $returnArr['data']['BedNo'] = $tesres['InPatientInfo']['BedNo'];             //床位号
            $returnArr['data']['Flag'] = $tesres['InPatientInfo']['Flag'];               //住院状态  1 待入科室 3 在科室 4 出院医嘱 5 出区，6 结算 7欠费结算  10 冻结 11 费用合并）
            $returnArr['data']['InDeptName'] = $tesres['InPatientInfo']['InDeptName'];   //入院科室名（入院）
            $returnArr['data']['DeptName'] = $tesres['InPatientInfo']['DeptName'];       //当前科室名（入院）  
            $returnArr['data']['InDate'] = $tesres['InPatientInfo']['InDate'];           //入院时间（入院）
            $returnArr['data']['InDiagnosisName'] = $tesres['InPatientInfo']['InDiagnosisName'];//入院诊断名称（入院）
            $returnArr['data']['PatientName'] = $tesres['InPatientInfo']['PatientName']; //病人姓名
            $returnArr['data']['PatientSex'] = $tesres['InPatientInfo']['PatientSex'];   //1男 2女 9未知
            $returnArr['data']['OrganCode'] = $tesres['InPatientInfo']['OrganCode'];     //院区 1001南院 1002 后湖 可以通过院区表识别
            $returnArr['data']['totalFee'] = $tesres['InPatientInfo']['totalFee'];       //总费用
            $returnArr['data']['depoisit'] = $tesres['InPatientInfo']['depoisit'];       //总预交金
            //echo $tesres['code'];
            if($tesres['code']=='201')
            {
                $returnArr['data']['datalist'] = '';    //
            } else if($tesres['code']=='200'){
                $te_arry=$tesres["InPatientInfo"]["datalist"]["T_HOSP_DEPOSIT"]["DepositId"];//判断是否二维数组
                $res_data=$tesres["InPatientInfo"]["datalist"]["T_HOSP_DEPOSIT"];
                if($te_arry)
                {
                    //echo 1;//一维数组
                    $returnArr['data']['datalist'][0]['DepositId']=$res_data['DepositId'];//预交金ID
                    $returnArr['data']['datalist'][0]['InpatientId']=$res_data['InpatientId'];//住院ID
                    $returnArr['data']['datalist'][0]['PayValues']=$res_data['PayValues'];//金额
                    $returnArr['data']['datalist'][0]['RecordType']=$res_data['RecordType'];//预交类型 10 预交 11 退预交
                    $returnArr['data']['datalist'][0]['PayMode']=$res_data['PayMode'];//付款方式，参考付款方式表：1 现金；10 110挂账；11 120挂账；12 GCP挂账；3 支票；4 代金卡；5 储值卡；6 欠费挂账；7 银行卡；8 支付宝；9 微信 
                    $returnArr['data']['datalist'][0]['BookUserId']=$res_data['BookUserId'];//创建人
                    $returnArr['data']['datalist'][0]['BookDate']=$res_data['BookDate'];    //创建日期
                    $returnArr['data']['datalist'][0]['ArriveBit']=$res_data['ArriveBit'];  //到账标记 0 未到账 1 到账
                    $returnArr['data']['datalist'][0]['ArriveDate']=$res_data['ArriveDate'];//到账时间
                    $returnArr['data']['datalist'][0]['ArriveUserId']=$res_data['ArriveUserId'];//到账操作人
                    $returnArr['data']['datalist'][0]['PayNo']=$res_data['PayNo'];//支付交易号 厂商流水号 对应住院预交金支付入参
                    $returnArr['data']['datalist'][0]['PayInfoOne']=$res_data['PayInfoOne'];//交易信息1 
                    $returnArr['data']['datalist'][0]['PayInfoTwo']=$res_data['PayInfoTwo'];//交易信息2 微信支付流水号
                    $returnArr['data']['datalist'][0]['Memo']=$res_data['Memo'];//备注
                    $returnArr['data']['datalist'][0]['DischargeBit']=$res_data['DischargeBit'];//结算标志 0 未结算 1结算
                    $returnArr['data']['datalist'][0]['BillNo']=$res_data['BillNo'];     //票据号
                    $returnArr['data']['datalist'][0]['OrganCode']=$res_data['OrganCode'];  //院区ID
                    $returnArr['data']['datalist'][0]['SerialNo']=$res_data['SerialNo'];    //机制号(发票号)
                } else{
                    //echo 2;//多维数组
                    foreach ($res_data as $k => $v) {
                        $returnArr['data']['datalist'][$k]['DepositId']=$res_data[$k]['DepositId'];//预交金ID
                        $returnArr['data']['datalist'][$k]['InpatientId']=$res_data[$k]['InpatientId'];//住院ID
                        $returnArr['data']['datalist'][$k]['PayValues']=$res_data[$k]['PayValues'];//金额
                        $returnArr['data']['datalist'][$k]['RecordType']=$res_data[$k]['RecordType'];//预交类型 10 预交 11 退预交
                        $returnArr['data']['datalist'][$k]['PayMode']=$res_data[$k]['PayMode'];//付款方式，参考付款方式表：1 现金；10 110挂账；11 120挂账；12 GCP挂账；3 支票；4 代金卡；5 储值卡；6 欠费挂账；7 银行卡；8 支付宝；9 微信 
                        $returnArr['data']['datalist'][$k]['BookUserId']=$res_data[$k]['BookUserId'];//创建人
                        $returnArr['data']['datalist'][$k]['BookDate']=$res_data[$k]['BookDate'];    //创建日期
                        $returnArr['data']['datalist'][$k]['ArriveBit']=$res_data[$k]['ArriveBit'];  //到账标记 0 未到账 1 到账
                        $returnArr['data']['datalist'][$k]['ArriveDate']=$res_data[$k]['ArriveDate'];//到账时间
                        $returnArr['data']['datalist'][$k]['ArriveUserId']=$res_data[$k]['ArriveUserId'];//到账操作人
                        $returnArr['data']['datalist'][$k]['PayNo']=$res_data[$k]['PayNo'];//支付交易号 厂商流水号 对应住院预交金支付入参
                        $returnArr['data']['datalist'][$k]['PayInfoOne']=$res_data[$k]['PayInfoOne'];//交易信息1 
                        $returnArr['data']['datalist'][$k]['PayInfoTwo']=$res_data[$k]['PayInfoTwo'];//交易信息2 微信支付流水号
                        $returnArr['data']['datalist'][$k]['Memo']=$res_data[$k]['Memo'];//备注
                        $returnArr['data']['datalist'][$k]['DischargeBit']=$res_data[$k]['DischargeBit'];//结算标志 0 未结算 1结算
                        $returnArr['data']['datalist'][$k]['BillNo']=$res_data[$k]['BillNo'];     //票据号
                        $returnArr['data']['datalist'][$k]['OrganCode']=$res_data[$k]['OrganCode'];  //院区ID
                        $returnArr['data']['datalist'][$k]['SerialNo']=$res_data[$k]['SerialNo'];    //机制号(发票号)
                    }
                }
            }
            
            //echo json_encode($returnArr);exit;
        } else{//格式化为标准接口模式
            $returnArr['status'] = 2;//返回失败
            $returnArr['errorMsg'] = $tesres['description'];
        }
        //dump($returnArr);
        echo json_encode($returnArr);
    }

    //一个接口的改进接口
    /**
     *根据住院号查询住院病人信息 //武汉市中心医院用--旧接口正式库
     * @param  $inPatientNo    '住院号'    
     */
    function getInPatientInfo_Old($hospitalId,$inPatientNo)
    {
        $as_zyh=$inPatientNo;
        //$as_zyh = '6169721';
        //$jj = 'tcwy';
        //$zsdz = 'http://192.168.0.20/yygh/n_yygh.asmx?wsdl';//旧接口测试地址
        $jj = C('requestId_Old');
        $soap = new \SoapClient(C('PAY_URL_API')); 
        $param=array(
                'as_clientid'=>$jj,
                'as_pwd'=>$jj, 
                'as_zyh'=>$as_zyh,               
        );
        $result=$soap->zy_brzhxx($param);
        $data=$result->zy_brzhxxResult; //返回状态
        if($data=='ok'){
            $tttt=$result->as_brzhxx;
            $res=explode('|', $tttt); 
            $returnArr['status'] = 1;
            $returnArr['errorMsg'] = '查询成功';
            $returnArr['data']['InpatientNo'] = $res[0];//住院号
            $returnArr['data']['PatientName'] = $res[1];//住院病人姓名
            $returnArr['data']['PatientSex'] = $res[2];//住院病人性别
            $returnArr['data']['BirthDate'] = $res[3];//出生日期
            $returnArr['data']['BedNo'] = $res[7].' '.$res[6];//床位
            //$returnArr['data']['Address'] = $res[7].' '.$res[5];//住院病人病区地址
            $returnArr['data']['InDate'] = $res[8]; //入院时间
            $returnArr['data']['TotalFee'] = $res[10]; //费用总额
            $returnArr['data']['DepoisitFee'] = $res[11];    // 已缴金额
            $returnArr['data']['YueFee'] = strval((float)$res[11]-(float)$res[10]);    // 余额
            //$returnArr['data']['YuanQu'] = $res[12];    //院区001 南京路院区002 后湖院区003 花桥院区 004 谌家矶院区
        } else
        {
            $returnArr['status'] = 2;
            $returnArr['errorMsg'] = $data;
        };
        //dump($returnArr);
        echo json_encode($returnArr);
    }

    /**
     * 住院预交金支付xml
     * */
    function get_PayInpatientDeposit_xml($InpatientId,$PayValues,$PayMode,$PayNo,$PayInfoOne,$PayInfoTwo,$Memo){
        $xml="<?xml version='1.0' encoding='utf-8'?><root><!--住院ID--><InpatientId>".$InpatientId."</InpatientId><!--金额--><PayValues>".$PayValues."</PayValues><!--付款方式--><PayMode>".$PayMode."</PayMode><!--支付交易号--><PayNo>".$PayNo."</PayNo><!--交易信息1--><PayInfoOne>".$PayInfoOne."</PayInfoOne><!--交易信息2--><PayInfoTwo>".$PayInfoTwo."</PayInfoTwo><!--备注--><Memo>".$Memo."</Memo></root>";
        return $xml;
    }

    /**
     *住院预交金支付 //武汉市中心医院用
     * @param  $inPatientNo    '住院号'    
     */
    function PayInpatientDeposit($hospitalId,$organCode,$InpatientId,$PayValues,$PayMode,$PayNo,$PayInfoOne,$PayInfoTwo,$Memo)
    {
        //$InpatientId = '53f39195-717b-48f3-8940-077cc5778bcd';
        /*$organCode = 1001;        //院区ID int
        $InpatientId = '53f39195-717b-48f3-8940-077cc5778bcd';//住院ID
        $PayValues = '100';   //金额
        $PayMode = '9';     //付款方式 9微信支付
        $PayNo = 'LSH201705260003';       //支付交易号 厂商流水号
        $PayInfoOne = '4007522001201705262478209527';  // 微信支付流水号
        $PayInfoTwo = '';  //交易信息2
        $Memo = '';        //备注*/
        $xmlStrinArge =$this->get_PayInpatientDeposit_xml($InpatientId,$PayValues,$PayMode,$PayNo,$PayInfoOne,$PayInfoTwo,$Memo);
        //dump($xmlStrinArge);
        $soap = new \SoapClient(C('PAY_URL_API')); 
        $result = $soap->PayInpatientDeposit( 
                C('as_clientid'),C('as_logpwd'),$organCode,$xmlStrinArge
            ); 
        $tesres_qbq = preg_replace('#<!--.*?-->#', '' , $result);//去掉标签注释
        $tesres = $this->xml_to_array($tesres_qbq);

        if($tesres['code']!='200'){
            $returnArr['status'] = 2;
            $returnArr['errorMsg'] = $tesres['description'];
        }else{//格式化为标准接口模式
            $returnArr['status'] = 1;
            $returnArr['errorMsg'] = $tesres['description'];
            $returnArr['data']['DepositId'] = $tesres['DepositId']; //预交金ID
            $returnArr['data']['SerialNo'] = $tesres['SerialNo'];   //机制号(发票号)
        }
        //dump($result);
        //dump($returnArr);
        echo json_encode($returnArr);
    }


    /**
     *住院预交金支付 //武汉市中心医院用 --旧接口正式库
     * @param  $inPatientNo    '住院号'    
     */
    function PayInpatientDeposit_Old($hospitalId,$as_zyh,$yjje,$openid,$lsh,$shh)
    {
        /*$as_zyh = '6169721';   //住院号
        $yjje = '0.01';         //预交金金额
        $openid = 'Txxffafafafeeafxxxfd';   //微信openid
        $lsh = '201706121001'; //流水号   商户订单号 腾楚医疗平台自己生成的订单号 需要往HIS和微信分别传值
        $shh ='10021159';           //商户号 微信返回值*/

        //$jj = 'tcwy';
        //$zsdz = 'http://192.168.0.20/yygh/n_yygh.asmx?wsdl';//旧接口测试地址
        $jj = C('requestId_Old');
        $soap = new \SoapClient(C('PAY_URL_API')); 
        $param=array(
                'as_clientid'=>$jj,
                'as_pwd'=>$jj, 
                'as_zyh'=>$as_zyh,  
                'as_jkje'=>$yjje,
                'as_shh'=>$shh,
                'as_zdh'=>'004507',
                'as_jysj'=>date('Y-m-d H:i:s',time()),
                'as_jsckh'=>'123',
                'as_yhkh'=>$openid,
                'as_kyxq'=>'',
                'as_bankno'=>$openid,
                'as_lsh'=>$lsh,
                'as_sjhm'=>'',             
        );
        $result=$soap->zy_yjk($param);
        $data=$result->zy_yjkResult; //返回值
        $data=explode('|', $data);
        if($data[0]=='1'){
            $returnArr['status'] = 1;
            $returnArr['errorMsg'] = '预交金缴费成功';
            $returnArr['as_sjhm'] = $result->as_sjhm;   //收据号码
        } else
        {
            $returnArr['status'] = 2;
            $returnArr['errorMsg'] = $data[1];
        }
        //dump($returnArr);
        echo json_encode($returnArr);
    }

    /**
     *根据病人ID查询处方明细--旧接口正式库
     * @param  $patientId    '病人ID'
     */
     function prePayDoorList_Old(/*$hospitalId, $id*/){
        //$id='1f901dce-7632-4284-9fbb-98986142148e';
        //$id='0a7e41ec-cb0f-48b2-a359-e26104925afb';
        //$id='3c8d0e5d-bda9-4956-aa04-14c27c6c27fc';
        $id='dd391b11-5da1-4e98-b2df-6a740aacf4d2';
        $as_clientid=C('as_clientid');
        $as_pwd='';
        $as_PatientId=$id;
        $soap = new \SoapClient(C('XIN_URL_API'));
        $result=$soap->GetOutpatientPescriptionListByPatientId($as_clientid,$as_pwd,$as_PatientId);
        $result=$this->xml_to_array($result);
        dump($result);die();

        $returnArr=array();
        if($result['description']=='成功'){
            $returnArr['status'] = 1;
            $returnArr['errorMsg'] = '查询成功';
        }else{
            $returnArr['status'] = 2;
            $returnArr['errorMsg'] = $result['description'];
        }
        if($result['RegisterList']['Register'][0]){
            //多个科室
            foreach ($result['RegisterList']['Register'] as $k2 => $v2) {
                $returnArr['data'][$k2]['RegisterId']=$v2['RegisterId'];
                $returnArr['data'][$k2]['RegDateTime']=$v2['RegDateTime'];
                $returnArr['data'][$k2]['DeptName']=$v2['DeptName'];
                $returnArr['data'][$k2]['AreaId']=$v2['AreaId'];
                $price='';
                if($v2['OutpatientPrescriptionlist']['OutpatientPrescription'][0]){
                    //多个处方条目
                    foreach ($v2['OutpatientPrescriptionlist']['OutpatientPrescription'] as $k3 => $v3) {
                        $returnArr['data'][$k2]['chufa'][$k3]['PrescriptionId']=$v3['PrescriptionId'];
                        $returnArr['data'][$k2]['chufa'][$k3]['PresType']=$v3['PresType'];
                        $returnArr['data'][$k2]['chufa'][$k3]['DoctorId']=$v3['DoctorId'];
                        if($v3['PrescriptionList']['PrescriptionListItem'][0]){
                            //多个门诊处方明细条目
                            foreach ($v3['PrescriptionList']['PrescriptionListItem'] as $k => $v) {
                                $returnArr['data'][$k2]['chufa'][$k3]['mingxi'][$k]['typename']=$v['OrderName'];
                                $returnArr['data'][$k2]['chufa'][$k3]['mingxi'][$k]['price']=$v['TotalMoney'];
                                $price+=$v['TotalMoney'];
                            }
                        }else{
                            //一个门诊处方明细条目
                            $returnArr['data'][$k2]['chufa'][$k3]['mingxi'][0]['typename']=$v3['PrescriptionList']['PrescriptionListItem']['OrderName'];
                            $returnArr['data'][$k2]['chufa'][$k3]['mingxi'][0]['price']=$v3['PrescriptionList']['PrescriptionListItem']['TotalMoney'];
                            $price+=$v3['PrescriptionList']['PrescriptionListItem']['TotalMoney'];
                        }
                    }
                }else{
                    //一个处方条目
                    $returnArr['data'][$k2]['chufa'][0]['PrescriptionId']=$v2['OutpatientPrescriptionlist']['OutpatientPrescription']['PrescriptionId'];
                    $returnArr['data'][$k2]['chufa'][0]['PresType']=$v2['OutpatientPrescriptionlist']['OutpatientPrescription']['PresType'];
                    $returnArr['data'][$k2]['chufa'][0]['DoctorId']=$v2['OutpatientPrescriptionlist']['OutpatientPrescription']['DoctorId'];
                    if($v2['OutpatientPrescriptionlist']['OutpatientPrescription']['PrescriptionList']['PrescriptionListItem'][0]){
                            //多个门诊处方明细条目
                        foreach ($v2['OutpatientPrescriptionlist']['OutpatientPrescription']['PrescriptionList']['PrescriptionListItem'] as $k => $v) {
                            $returnArr['data'][$k2]['chufa'][0]['mingxi'][$k]['typename']=$v['OrderName'];
                            $returnArr['data'][$k2]['chufa'][0]['mingxi'][$k]['price']=$v['TotalMoney'];
                            $price+=$v['TotalMoney'];
                        }
                    }else{
                        //一个门诊处方明细条目
                        $returnArr['data'][$k2]['chufa'][0]['mingxi'][0]['typename']=$v2['OutpatientPrescriptionlist']['OutpatientPrescription']['PrescriptionList']['PrescriptionListItem']['OrderName'];
                        $returnArr['data'][$k2]['chufa'][0]['mingxi'][0]['price']=$v2['OutpatientPrescriptionlist']['OutpatientPrescription']['PrescriptionList']['PrescriptionListItem']['TotalMoney'];
                        $price+=$v2['OutpatientPrescriptionlist']['OutpatientPrescription']['PrescriptionList']['PrescriptionListItem']['TotalMoney'];
                    }
                }
                $returnArr['data'][$k2]['price']=$price;
            }
            //dump($returnArr);
        }else{
            //一个科室
            $returnArr['data'][0]['RegisterId']=$result['RegisterList']['Register']['RegisterId'];
            $returnArr['data'][0]['RegDateTime']=$result['RegisterList']['Register']['RegDateTime'];
            $returnArr['data'][0]['DeptName']=$result['RegisterList']['Register']['DeptName'];
            $returnArr['data'][0]['AreaId']=$result['RegisterList']['Register']['AreaId'];
            $price='';
            if($result['RegisterList']['Register']['OutpatientPrescriptionlist']['OutpatientPrescription'][0]){
                    //多个处方条目
                    foreach ($v2['OutpatientPrescriptionlist']['OutpatientPrescription'] as $k3 => $v3) {
                        $returnArr['data'][0]['chufa'][$k3]['PrescriptionId']=$v3['PrescriptionId'];
                        $returnArr['data'][0]['chufa'][$k3]['PresType']=$v3['PresType'];
                        $returnArr['data'][0]['chufa'][$k3]['DoctorId']=$v3['DoctorId'];
                        if($v3['PrescriptionList']['PrescriptionListItem'][0]){
                            //多个门诊处方明细条目
                            foreach ($v3['PrescriptionList']['PrescriptionListItem'] as $k => $v) {
                                $returnArr['data'][0]['chufa'][$k3]['mingxi'][$k]['typename']=$v['OrderName'];
                                $returnArr['data'][0]['chufa'][$k3]['mingxi'][$k]['price']=$v['TotalMoney'];
                                $price+=$v['TotalMoney'];
                            }
                        }else{
                            //一个门诊处方明细条目
                            $returnArr['data'][0]['chufa'][$k3]['mingxi'][0]['typename']=$v3['PrescriptionList']['PrescriptionListItem']['OrderName'];
                            $returnArr['data'][0]['chufa'][$k3]['mingxi'][0]['price']=$v3['PrescriptionList']['PrescriptionListItem']['TotalMoney'];
                            $price+=$v3['PrescriptionList']['PrescriptionListItem']['TotalMoney'];
                        }
                    }
                }else{
                    //一个处方条目
                    $returnArr['data'][0]['chufa'][0]['PrescriptionId']=$result['RegisterList']['Register']['OutpatientPrescriptionlist']['OutpatientPrescription']['PrescriptionId'];
                    $returnArr['data'][0]['chufa'][0]['PresType']=$result['RegisterList']['Register']['OutpatientPrescriptionlist']['OutpatientPrescription']['PresType'];
                    $returnArr['data'][0]['chufa'][0]['DoctorId']=$result['RegisterList']['Register']['OutpatientPrescriptionlist']['OutpatientPrescription']['DoctorId'];
                    if($result['RegisterList']['Register']['OutpatientPrescriptionlist']['OutpatientPrescription']['PrescriptionList']['PrescriptionListItem'][0]){
                            //多个门诊处方明细条目
                        foreach ($result['RegisterList']['Register']['OutpatientPrescriptionlist']['OutpatientPrescription']['PrescriptionList']['PrescriptionListItem'] as $k => $v) {
                            $returnArr['data'][0]['chufa'][0]['mingxi'][$k]['typename']=$v['OrderName'];
                            $returnArr['data'][0]['chufa'][0]['mingxi'][$k]['price']=$v['TotalMoney'];
                            $price+=$v['TotalMoney'];
                        }
                    }else{
                        //一个门诊处方明细条目
                        $returnArr['data'][0]['chufa'][0]['mingxi'][0]['typename']=$result['RegisterList']['Register']['OutpatientPrescriptionlist']['OutpatientPrescription']['PrescriptionList']['PrescriptionListItem']['OrderName'];
                        $returnArr['data'][0]['chufa'][0]['mingxi'][0]['price']=$result['RegisterList']['Register']['OutpatientPrescriptionlist']['OutpatientPrescription']['PrescriptionList']['PrescriptionListItem']['TotalMoney'];
                        $price+=$result['RegisterList']['Register']['OutpatientPrescriptionlist']['OutpatientPrescription']['PrescriptionList']['PrescriptionListItem']['TotalMoney'];
                    }
                }
            $returnArr['data'][0]['price']=$price;
            //dump($returnArr);
        }
        //dump($returnArr);die();
        echo json_encode($returnArr);
    }

    //门诊预结算(生成订单)
    function xinMenOrder($hospitalId,$RegisterId,$FeeTypeId,$MedicareAccountPay,$MedicarePay,$PrescriptionId){
        $fileContent = $hospitalId.'+'.$RegisterId.'+'.$FeeTypeId.'+'.$MedicareAccountPay.'+'.$MedicarePay.'+'.$PrescriptionId;
$dir = "soapGetDate/";
\Org\Util\File::createDir($dir);
file_put_contents($dir . $Flag . "yiyi.txt", $fileContent);
        //header("Content-type:text/xml;charset=utf-8");
        /*$RegisterId='85315f21-a79b-4a2b-bf90-a7c100af9305';//挂号id
        $FeeTypeId=0;//0.自费 1.医保
        $MedicareAccountPay=0;//医保账户decimal 自费时传0
        $MedicarePay=0;//医保支付金额 decimal 自费时传0
        $PrescriptionId='fccaeebd-81da-4eeb-89ce-a7c100b03af8';*/
        $res=explode(',',$PrescriptionId);
        $xml='<?xml version="1.0" encoding="utf-8" ?>
<root>
  <HospitalId>1000</HospitalId>
  <AreaId>1001</AreaId>
  <RegisterId>'.$RegisterId.'</RegisterId>
  <RoundNum>0</RoundNum>
  <FeeTypeId>'.$FeeTypeId.'</FeeTypeId>
  <MedicareAccountPay>'.$MedicareAccountPay.'</MedicareAccountPay>
  <MedicarePay>'.$MedicarePay.'</MedicarePay>
  <datalist>';
        foreach ($res as $k => $v) {
            $xml.='<PrescriptionId>'.$v.'</PrescriptionId>';
        }
        $xml.='</datalist></root>';
        $as_clientid=C('as_clientid');
        $as_pwd='';
        $as_PatientId=$id;
        $soap = new \SoapClient(C('XIN_URL_API'));
        $result=$soap->ExpenseSettlement($as_clientid,$as_pwd,$xml);
        $result=$this->xml_to_array($result);
        $returnArr=array();
        if($result['description']=='成功'){
            $returnArr['status'] = 1;
            $returnArr['errorMsg'] = '查询成功';
            $returnArr['TotalCost']=$result['TotalCost'];//支付金额
            $returnArr['SettlementId']=$result['SettlementId'];//支付订单号
        }else{
            $returnArr['status'] = 2;
            $returnArr['errorMsg'] = $result['description'];
        }
        //dump($returnArr);
        echo json_encode($returnArr);
    }

    /**
     *门诊缴费--旧接口正式库
     * @param  $patientId    '病人ID'
    */
    function GetPayInfoBySettlementId_Old($hospitalId,$SettlementId,$FeeTypeId,$PayTypeId,$PayTypeName,$Money,$ActualRecive,$TradeMoney,$SerialNo,$BusinessId){

        $fileContent = $hospitalId.'+'.$SettlementId.'+'.$FeeTypeId.'+'.$PayTypeId.'+'.$PayTypeName.'+'.$Money.'+'.$ActualRecive.'+'.$TradeMoney.'+'.$SerialNo.'+'.$BusinessId;
$dir = "soapGetDate/";
\Org\Util\File::createDir($dir);
file_put_contents($dir . $Flag . "yiyi.txt", $fileContent);

        /*$SettlementId='d90e72aa-7b63-44f9-8e10-2af0f6a55449';//结算ID
        $FeeTypeId=0;//0.自费 1.医保
        $PayTypeId=9;//支付方式
        $PayTypeName='门诊缴费';//支付方式名称
        $Money='46.05';//扣除医保报销部分的自费金额
        $ActualRecive='46.05';//实收
        $TradeMoney='46.05';//交易金额
        $SerialNo='900913201707311621342';//交易流水号[厂商流水号]
        $BusinessId='4001872001201707313662088955';//商户订单号（支付宝）*/
        $as_clientid=C('as_clientid');
        $as_pwd='';
        $soap = new \SoapClient(C('XIN_URL_API'));
        $xml='<?xml version="1.0" encoding="utf-8" ?>
<root>
  <SettlementId>'.$SettlementId.'</SettlementId>
  <FeeTypeId>'.$FeeTypeId.'</FeeTypeId>
  <PayInfoList>
    <PayInfo>
      <PayTypeId>'.$PayTypeId.'</PayTypeId>
      <PayTypeName>'.$PayTypeName.'</PayTypeName>
      <Money>'.$Money.'</Money>
      <ActualRecive>'.$ActualRecive.'</ActualRecive>
      <OddMoney>0</OddMoney>
      <Round>0</Round>
      <TradeMoney>'.$TradeMoney.'</TradeMoney>
      <SerialNo>'.$SerialNo.'</SerialNo>
      <OrginalResult></OrginalResult>
      <CardNo></CardNo>
      <BusinessId>'.$BusinessId.'</BusinessId>
      <Reserve></Reserve>
      <CardType></CardType>
      <CardName></CardName>
      <LRC></LRC>
      <TradeCompany></TradeCompany>
      <TerminalNo></TerminalNo>
      <BatchNo></BatchNo>
      <ReferenceNo></ReferenceNo>
    </PayInfo>
  </PayInfoList>
</root>';
        $result=$soap->UpdatePayInfo($as_clientid,$as_pwd,$xml);
        $result=$this->xml_to_array($result);

        $fileContent = json_encode($result);
$dir = "soapGetDate/";
\Org\Util\File::createDir($dir);
file_put_contents($dir . $Flag . "yiyis.txt", $fileContent);

        dump($result);
    }

    /**
     *科室列表
     * @param  $patientId    '病人ID'
     */
     function queryDoctorInfos()
    {
        $id = 'A0A2EA33-06E6-459E-A82F-D3A506CD593D';
        //$doctorid = '1010';
        $soap = new \SoapClient('http://192.168.0.79:3333/DoctorInfoService.asmx?wsdl');
        //dump($soap);die();
        $param["id"]=$id;
        //$result=$soap->queryAllDoctorId($param);
        //$data=$result->queryAllDoctorIdResult;
        $result=$soap->queryAllNewDoctorId($param);
        $data=$result->queryAllNewDoctorIdResult;
        $tesres = $this->xml_to_array($data);
        //dump($tesres);
        if($tesres["documentinfo"]["resultcode"]!='100'){
            $returnArr['status'] = 2;
            $returnArr['errorMsg'] = $tesres["documentinfo"]["resultinfo"];
            //echo json_encode($returnArr);exit;
        }else{//格式化为标准接口模式
            $returnArr['status'] = 1;
            $returnArr['errorMsg'] = $tesres["documentinfo"]["resultinfo"];
            $res_data=$tesres["documentinfo"]["root"]["department"];
            foreach ($res_data as $k => $v) {
                $returnArr['data'][$k]['Deptxh']=$k+1; //科室名称
                $returnArr['data'][$k]['Deptname']=$res_data[$k]["@attributes"]['name']; //科室名称

                $res2_data=$res_data[$k]["doctorid"];
                if(is_array($res2_data))
                {
                    //echo [$k].‘ 是数组’;
                    foreach ($res2_data as $k2 => $v2) {
                        $returnArr['data'][$k]['doclist'][$k2]['doctorid']=$res2_data[$k2];//医生ID
                    }
                } else {
                    //echo [$k].‘ 不是数组’;
                    $returnArr['data'][$k]['doclist'][0]['doctorid']=$res2_data;//医生ID
                }
            }
        }
        foreach ($returnArr['data'] as $k => $v) {
            $str='';
            foreach ($v['doclist'] as $k2 => $v2) {
                $str.=$v2['doctorid'].',';
            }
            $returnArr['data'][$k]['doclist']=rtrim($str,',');
        };


        //dump($returnArr);
        echo json_encode($returnArr);    
    }

    /**
     *科室下面的医生详细介绍
     * @param  $doctorid    '医生ID'
     */
     function queryDoctorInfoByOldId($hospitalId,$doctorid)
    {
        $id = 'A0A2EA33-06E6-459E-A82F-D3A506CD593D';//医院分配的渠道ID
        //$doctorid = '1271';//医生ID
        $soap = new \SoapClient('http://192.168.0.79:3333/DoctorInfoService.asmx?wsdl');
        //dump($soap);die();
        $param["id"]=$id;
        $param["doctorid"]=$doctorid;

        //$result=$soap->queryDoctorInfoByOldId($param);
        //$data=$result->queryDoctorInfoByOldidResult;

        $result=$soap->queryDoctorInfo($param);
        $data=$result->queryDoctorInfoResult;
        $tesres = $this->xml_to_array($data);
        if($tesres["documentinfo"]["resultcode"]!='100'){
            $returnArr['status'] = 2;
            $returnArr['errorMsg'] = $tesres["documentinfo"]["resultinfo"];
        }else{//格式化为标准接口模式
            $returnArr['status'] = 1;
            $returnArr['errorMsg'] = $tesres["documentinfo"]["resultinfo"];
            $returnArr['data']['Doctorid'] = $doctorid;//医生ID
            $returnArr['data']['Doctorsname'] = $tesres["documentinfo"]["root"]["name"];//医生姓名
            $returnArr['data']['Deptname'] = $tesres["documentinfo"]["root"]["department"];//科室
            $returnArr['data']['zc'] = $tesres["documentinfo"]["root"]["zc"];//医生职称
            $returnArr['data']['zjjj'] = $tesres["documentinfo"]["root"]["zjjj"];//医生简介
            $returnArr['data']['sc'] = $tesres["documentinfo"]["root"]["sc"];//医生擅长
            $returnArr['data']['photo'] = $tesres["documentinfo"]["root"]["photo"];//医生图片文件名
        }

        //dump($data);
        //dump($returnArr);
        echo json_encode($returnArr);
    }

    /**
     *门诊缴费查询是否缴费成功 //武汉市中心医院用
     * @param  $as_ddh    '商户订单号'    
     */
    function PayOutpaitentInquire_Old($out_trade_no)
    {
        //$as_ddh = '53311201706220858302';   //商户订单号-腾楚产生
        $as_ddh = $out_trade_no;    //商户订单号-腾楚产生
        $as_fph ='';

        $zsdz = 'http://192.168.0.153/LISchaxun.asmx?wsdl';//旧接口测试地址http://192.168.0.153/LISchaxun.asmx?op=mzjs_chaxun
        $soap = new \SoapClient($zsdz); 
        $param=array(
                'postracenum'=>$as_ddh,
                'fph'=>$as_fph,
            );
        $result=$soap->mzjs_chaxun($param);
        $data=$result->mzjs_chaxunResult; //返回值
        
        if($data!='false'){
            $returnArr['status'] = 1;
            $returnArr['errorMsg'] = '门诊缴费成功！';
            $returnArr['fph'] = $data;
        } else{
            $returnArr['status'] = 2;
            $returnArr['errorMsg'] = '门诊缴费失败！';
            $returnArr['fph'] = '';
        };
        //dump($returnArr);
        echo json_encode($returnArr);
    }

    /**
     *取一个医生的排班列表
     * @param  $doctorid    '医生ID'
     */
}
?>